How can I accomplish that? Something like $(PullRequest.Tag) Thanks!
There's no predefined variable for Pull Request tag. (I use printenv
command in CMD task to confirm this!)
Here're my workaround:
Use Powershell task to call this rest api, the response would contain the tag of specific PR
$url = "$($env:SYSTEM_TEAMFOUNDATIONSERVERURI)$env:SYSTEM_TEAMPROJECTID/_apis/git/repositories/$($env:BUILD_REPOSITORY_NAME)/pullRequests/$($env:SYSTEM_PULLREQUEST_PULLREQUESTID)/labels?api-version=5.1-preview.1"
$response = Invoke-RestMethod -Uri $url -Method Get -Headers @{
Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"
}
Write-Host "##vso[task.setvariable variable=PullRequestTag;isOutput=true]$($response.value.name)"
Then pass the variable $response.value.name
(come from rest api response, the name represents the tag name) to output variable PullRequestTag(custom variable) so that next tasks can access the returned tag name.
Notes:
1.Make sure the job which contains the Powershell task allow scripts to access the OAuth token cause my script uses OAuth token instead of PAT to call rest api. (Click Agent Job Name=>Additional options)

2.Since it's a output variable, we should use format $(referenceName.variablename)
.


After that, we can use $(PS.PullRequestTag)
in next tasks to access the tag name.
3.Since your scenario is in a pipeline run triggered by PR, so actually the Powershell task should only run when current pipeline is triggered by PR instead of manual run/CI.
Use and(succeeded(), eq(variables['Build.Reason'], 'PullRequest'))
in PS task's control options. See conditions and Build.Reason variable.
Update:
If I added several tags when creating the PR:

The $(PS.PullRequestTag)
's value would be:
