Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using 'replace' expression in Azure Devops pipeline

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’ll setup a separate pipeline to test this, but I figured possibly I’m doing something obvious wrong?

>Solution :

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/', '')]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading