It looks that this info is not avialable in variables (yet). I tried these variables:
- script: |
echo '$(Build.TriggeredBy.BuildNumber)'!
echo '$(Build.TriggeredBy.BuildId)'!
echo '$(Build.TriggeredBy.DefinitionId)'!
echo '$(Build.TriggeredBy.DefinitionName)'!
echo '$(Build.TriggeredBy.ProjectID)'!
echo '$(Build.BuildNumber)'!
echo '$(Build.RequestedFor)'!
echo '$(Build.RequestedForEmail)'!
echo '$(Build.RequestedForId)'!
and this is what I got:
$(Build.TriggeredBy.BuildNumber)!
$(Build.TriggeredBy.BuildId)!
$(Build.TriggeredBy.DefinitionId)!
$(Build.TriggeredBy.DefinitionName)!
$(Build.TriggeredBy.ProjectID)!
20200901.12!
Microsoft.VisualStudio.Services.TFS!
!
00000002-0000-8888-8000-000000000000!
So I got meaningful value only for $(Build.BuildNumber)
.
So to get build number of your pipeline trigger you may use REST API:
variables:
devopsAccount : 'thecodemanual'
projectName : 'DevOps Manual'
steps:
- pwsh: |
# Get a build info
$uri = "https://dev.azure.com/$(devopsAccount)/$(projectName)/_apis/build/builds/$(Build.BuildId)?api-version=6.0-preview.6&expand=all"
Write-Host $uri
# Invoke the REST call
$result = Invoke-RestMethod -Uri $uri -Method Get -Headers @{Authorization = "Bearer $env:SYSTEM_ACCESSTOKEN"}
$buildNumber = $result.triggerInfo.version
Write-Host $buildNumber
echo "##vso[task.setvariable variable=triggeredByBuildNumber]$buildNumber"
- script: |
echo '$(triggeredByBuildNumber)'!
With this approach I retrieved 20200901.14
which is correct value of my build trigger.
And trigger info has more details:
"triggerInfo": {
"artifactType": "Pipeline",
"alias": "test",
"projectId": "4fa6b279-3db9-4cb0-aab8-e06c2ad550b2",
"pipelineTriggerType": "PipelineCompletion",
"source": "kmadof.dm-so-46",
"pipelineId": "3320",
"version": "20200901.14"
},
if you need some.
$(Build.TriggeredBy.BuildNumber)
might be what you are looking for if your CD pipeline is automatically triggered by CI run. Documented HERE – LJ.