Sample from yml file:
pool:
name: Managed
demands:
- agent.name -equals Agent2
# Overrides the value for Build.BuildNumber, which is used to name the artifact (ZIP file) that is produced
name: '$(Date:yyyyMMdd)T$(Hours)$(Minutes)$(Seconds)'
resources:
repositories:
- repository: RepoA
type: git
ref: release/X
name: company/RepoA
trigger:
branches:
include:
- release/X
- repository: RepoB
type: git
ref: release/X
name: company/RepoB
trigger:
branches:
include:
- release/X
... <more repos and other stuff to build the app> ...
Our application is split into multiple repos. Whenever a commit is made to any repo the pipeline should trigger and build the application (using all repos).
The issue occurs when I work on a feature where I have to make changes to both repos here. That results technically results in two commits (one for RepoA and one for RepoB), which means that this pipeline will trigger twice. This in itself it not so bad since we are self-hosting and don’t pay per run, but the issue is that sometimes the first run will fail, because it does not have the updated code from the other repo. This must be some internal limitation of how Azure works.
This means that in a scenario with a commit to both repos (that is done at the same time), two runs will happen. First run fails, then the second run will start directly after and succeed.
Two questions:
- Why is this happening?
- How, if possible, can we fix this?
2
Answers
Regarding your first question, please refer to this section of the documentation:
In other words, when your pipeline is triggered by
RepoA
, it will check out the latest commit from therelease/X
branch inRepoB
. The pipeline might fail if the checkout in the pipeline occurs before the new commit is finalized inRepoB
. However, as soon as the second pipeline is triggered byRepoB
, the commit inRepoA
has already been completed, resulting in a successful pipeline execution.Regarding your second question, it’s unlikely that this behavior can be fixed in Azure DevOps, as the system is functioning as intended. The only potential workaround, albeit not an elegant solution, would be to incorporate a delay and clone the non-triggering repository in a subsequent script.
If this issue poses a significant problem for your workflow, you may need to reconsider and adapt your strategy regarding your repositories.
Specifying a trigger section for multiple repository resources means that any change to these resources will initiate a new run. When you commit changes to both
RepoA
andRepoB
, Azure Pipelines triggers a build for each commit. You can refer the triggers document for multiple repositories for more details.You mentioned a scenario with a commit to both repos (that is done at the same time), in the system they are two commits that are processed independently, one after the other. Therefore, the first build does not have the latest changes from the other repository, resulting in failure.
From the document:
This function is intended for the above scenarios.
Currently, there is no option to disable the first run for your scenario. As a workaround, you may:
If the above workaround does not meet your needs, you can request the feature for Azure DevOps here to help the feature better. Engineers usually prioritize features that are urgent or have more votes.