Reputation: 3915
I'm building a CI pipeline within azure pipelines and am struggling with the following, I have a buildstep that is always triggered. Hence I give my image the commit hash as tag for future reference. However, I want to add the gittag name whenever this has triggered the push. Is there a way to conditionally add this tag? My current task is:
- task: Docker@2
inputs:
containerRegistry: 'my-registry'
repository: '$(System.TeamProject)/$(Build.Repository.Name)'
command: 'buildAndPush'
Dockerfile: 'Dockerfile'
tags: |
$(Build.SourceVersion)
$(Build.SourceBranchName)
This adds the tag, but whenever a commit to a branch was the trigger I also get a branch tag (develop / main), I'd like to prevent this.
Upvotes: 1
Views: 2467
Reputation: 13479
In YAML pipeline, you can use the if
expression to conditionally set a task input dynamically (see here).
With this feature, you can set different values to an input of the task in different conditions. This should be able to meet your demands.
Upvotes: 1