I have an Azure DevOps pipeline with 3 stages in it.
Stage 1: Checkout the self repository. Create folders. Push the changes back to the repo
Stage 2: Checkout the self repository. Create files in the above mentioned folders. Push the changes.
Stage 3: Checkout the self repo. Read the previously created files.
My issue is that even though I push the changes back in Stage 1, when Stage 2 makes the checkout it cannot see these new folders.
So when I run my pipeline it creates the folders, but Stage 2 fails because it cannot see the folders. If I rerun the pipeline the folders are there, so Stage 2 can also succeed, create the files and push them, but Stage 3 won't see these files yet so it will fail. So, I have to run my pipeline 3 times to make it succeed.
It looks like even though the three stages run after one another, and I do separate checkout in all of them, somehow they still download the same initial version of the repository. So even though the checkout of Stage 2 happens after the push of Stage 1, Stage 2 still cannot see the changes made by Stage 1.
Is this a normal behavior? I assumed there are some caching that makes the stages use the same version of the files. If so, is it possible to change this behavior? I don't really have any other idea of what could be the issue here.
I can reproduce the same situation. And I can confirm that this is an expected behavior.
When a pipeline is queued the ref is set. All Stages/jobs in the pipeline will checkout the same reference. This is how Pipeline works.
We can get the ref info in the Pipeline summary Page:
is it possible to change this behavior?
I am afraid that there is no out-of-box method can directly change this behavior.
For a workaround, you can add git pull or git fetch command in stage to sync the changes in remote azure repo.
For example: git pull origin HEAD:main
- stage: stagename
jobs:
- job:
steps:
- checkout: self
persistCredentials: true
- powershell: |
git pull origin HEAD:main
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
xxxx
git add .
git commit -m "123"
git push origin HEAD:main