I have a script task in an ADO Pipeline which sets a pipeline build tag:
echo "##vso[build.addbuildtag]MyTag foo"
Now I am looking if there is a way to read that tag in other task (in different jobs/stages) from within that same pipeline?
I have a script task in an ADO Pipeline which sets a pipeline build tag:
echo "##vso[build.addbuildtag]MyTag foo"
Now I am looking if there is a way to read that tag in other task (in different jobs/stages) from within that same pipeline?
You can use rest api to get build info:
pool:
name: Azure Pipelines
steps:
- powershell: 'Write-Host "##vso[build.addbuildtag]build_1"'
displayName: 'Set tag'
- powershell: |
$token = "$(System.AccessToken)"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$orgUrl = "$(System.CollectionUri)"
$teamProject = "$(System.TeamProject)"
$buildId = '$(Build.BuildId)'
$buildDefId = '$(System.DefinitionId)'
$restGetBuildLogs = "$orgUrl/$teamProject/_apis/build/builds/$buildId" + "?api-version=6.0"
function InvokeGetRequest ($GetUrl)
{
return Invoke-RestMethod -Uri $GetUrl -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
}
$build = InvokeGetRequest $restGetBuildLogs
Write-Host $build.tags
displayName: 'Read tag'
You can use variables and logging commands. Example with PowerShell:
pool:
name: Azure Pipelines
variables:
my.tag: ''
steps:
- powershell: |
Write-Host "##vso[task.setvariable variable=my.tag;]build_1"
displayName: 'Set var value'
- powershell: |
Write-Host "##vso[build.addbuildtag]$(my.tag)"
displayName: 'Set tag'
- powershell: |
Write-Host "$(my.tag)"
displayName: 'View tag'