azure-devopsazure-pipelinescontinuous-delivery

How to automatically create a Build Pipeline TAG (not a GIT TAG) after a successful build?


The story so far:

This is where the help is needed.

I have hunted high and low for days for a way to automatically create the PipeLine Build TAG and only find answers to what I already have in place. I don't might if it is a step/task in YAML or a setting in the Build Pipeline. If anyone can point me in the right direction I'd be most grateful.

The end goal is to push the original source GIT TAG into the Build TAG if the build is successful.

Notes: I'm working only in YAML and what ever setting come nativly with Azure Devops Version Dev18.M170.1, ie no plugins.


Solution

  • If still in the build phase, you can add a build tag bu running the following command from a script, bash or PowerShell (write-host instead of echo) task:

    echo "##vso[build.addbuildtag]My Tag"
    

    In Yaml the simplest syntax would be:

    - script: |
        echo "##vso[build.addbuildtag]My Tag"
    

    Or for PowerShell you can use the short syntax:

    steps:
    - powershell: |
        $newSourceBranch = "$(Build.SourceBranch)" -replace 'refs/tags/', '' 
        $Command = "##vso[build.addbuildtag]"+$newSourceBranch 
        write-host "Create a Build TAG called $newSourceBranch" 
        write-host $Command