1

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?

1

1 Answer 1

2

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/', '')]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.