Reputation: 97
I'm trying to build and tag a container image based on the git branch I'm building.
ADO has two options for the branch name:
Build.SourceBranch
eg. refs/heads/rc/1.0.0
or
Build.SourceBranchName
eg. 1.0.0
However I want to tag my image using rc1.0.0
, and I figured that should be possible by initially in my yml defining a variable using:
variables:
temp: ${{replace('$(Build.SourceBranch)', 'refs/heads/', '')}}
dockertag: ${{replace('$(temp)','/','')}}
However when I bash: echo '$(dockertag)'
it produces refs/heads/master
for the master branch where I would have expected master
instead.
I'll setup a separate pipeline to test this, but I figured possibly I'm doing something obvious wrong?
Upvotes: 1
Views: 7138
Reputation: 48
Replacing characters in strings and branches has been covered here: How to replace in variable strings inside azure-pipelines.yaml?
In short try:
variables:
suffix: $[replace(variables['build.sourcebranchname'], 'refs/heads/', '')]
Upvotes: 2