Set Tag in Release Azure Devops

Viewed 94

I have a problem in CI/CD. Set automatized add tag in release pipeline, for intern step(task or PowerShell) in release

example in powershell in build pipe:

Write-Host "##vso[build.addbuildtag]$(ENVIRONMENT)

add field manually:

enter image description here

1 Answers

The logging command you are using is to add build tags, it's not applied to release. See Logging commands for details.

We can add release tags by add a PowerShell task to run a script calling the REST API, below sample for your reference:

  1. Grant the Release Manage permission for the account "Artifacts Build Service (xxx)"

Go to Pipelines > Release > Security > Search for "Artifacts Build Service (xxx)" account, and set the Manage Releases permission to Allow enter image description here

  1. Edit the release pipeline, enable the option "Allow scripts to access the OAuth token" in Agent Job. enter image description here

  2. Add a PowerShell task at the end of the pipeline and run the following script to call the REST API to add release tags.

Write-Host "TAG:" $(ENVIRONMENT)   
$url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)Artifacts/_apis/Release/releases/$($env:RELEASE_RELEASEID)/tags/$(ENVIRONMENT)?api-version=7.1-preview.1"
Write-Host "URL: $url"
Invoke-RestMethod -Uri $url -Method PATCH -ContentType "application/json" -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}`

enter image description here

  1. Create a release, refresh the page after the release completed, check the result. enter image description here

enter image description here

Related