Reputation: 195
I have a multistage YAML Azure pipeline. I tag my images based on the build ID. This works well until a job fails and I need to rerun it.
On the rerun I get a newly incremented build Id so it no longer references same docker image used in the original run.
$(Build.BuildId)
Is there anyway around this?
Upvotes: 0
Views: 179
Reputation: 31013
You could expand stage and rerun the stage, this won't change the buildId:
Upvotes: 2
Reputation: 40583
Re-running job or stage doesn't change Build.BuildId
. I checked this using below pipeline. However if you want to run whole pipeline for the same build id you my try to use runtime paramaters and provide a tagName on your own (like below):
parameters:
- name: tagName
type: string
default: ' '
trigger: none
pr: none
pool:
vmImage: 'ubuntu-latest'
stages:
- stage: A
jobs:
- job: A
steps:
- pwsh: |
$tagName = '$(Build.BuildId)'
if('${{ parameters.tagName }}' -ne ' ') {
$tagName = '${{ parameters.tagName }}'
}
echo $tagName
- job: B
steps:
- bash: echo "B"
- stage: B
jobs:
- job: A
steps:
- pwsh: |
$tagName = '$(Build.BuildId)'
if('${{ parameters.tagName }}' -ne ' ') {
$tagName = '${{ parameters.tagName }}'
}
echo $tagName
- bash: exit 1
- job: B
steps:
- bash: echo "B"
Upvotes: 2