Search code examples
azure-devopsbranching-and-mergingtaggingazure-devops-extensions

How to Tag a branch Automatically in Azure DevOps using extension (Tag/Branch Git On Release)


With Azure DevOps release pipeline I'm planning to tag my brach Automatically by using the below extension which was created by Micheal Barry Tag\Branch Git on Release. See the below image:

enter image description here

I'm a bit wondering how to customize Tag name as UAT_$(date:yyyyMMdd)$(Rev:.r). Since this has limited documentation, this is how I try to add(See below)

How can I achieve this? Also, I'm more interested in how to fill these advanced options for this extension.

enter image description here


Solution

  • The $(date:yyyyMMdd)$(Rev:.r) is only supported in BuildNumber (Options=>Build Number Format) and ReleaseNumber (Options=>Release Name format). So if you put $(date:yyyyMMdd)$(Rev:.r) directly in Static Tag Name, the task can't evaluate its value.

    Here're several directions to do what you want:

    1. Use $(date:yyyyMMdd)$(Rev:.r) as release name format.

    enter image description here

    Then use UAT_$(Release.ReleaseName) in Static Tag Name input.

    enter image description here

    The result:

    enter image description here

    PS: If you set build pipeline as release pipeline's artifact source, you can also use $(Build.BuildNumber)/$(Build.DefinitionName) in your Release name format.

    2.If you prefer to use Release-$(date:yyyyMMdd)$(Rev:.r) as release name format. Now since what you want is UAT_xxx, you need to use the Regex option:

    enter image description here

    Assuming your release name's instance is Release-20200518.5, now the tag would be UAT_20200518.5 if you configure the task following my inputs above.

    In addition:

    When release name format is $(date:yyyyMMdd)$(Rev:.r), you releases would be:

    enter image description here

    You can choose to use the Static Tag Name, check #1 above.

    And when the name format is Release-$(date:yyyyMMdd)$(Rev:.r), you releases would be:

    enter image description here

    You should use regex option in that third-party task, check #2 above. About what is Regex see here, also there's many documents/blogs online about Regex topic...