Search code examples
azure-devopsyamlazure-pipelinesazure-pipelines-release-pipeline

Getting the latest build id from a referenced pipeline resource


In the classic release pipeline it was possible to add other pipelines as Artifact resources - these could be triggers, or just references. You could then reference information about them, e.g. the build id using $(Release.Artifacts.ARTIFACTNAME.BuildId).

You can now do something similar in a multi-stage yaml pipeline:

resources:
  pipelines:
  - pipeline: MyBuild
    source: My build pipeline name 
    trigger: 
      branches:
      - master

steps:
- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: Write-Host Referenced pipeline build id is: ???

But as per the PowerShell step above, I can't find a way to get the build id of a resource associated in this way, and I can't spot anything in the documentation yet.

Some desperate attempts I've made are:

$(Release.Artifacts.MyBuild.BuildId)
$(resources.MyBuild.BuildId)
$(BuildId@MyBuild)

Does anyone know how this can be done?


Solution

  • The newest release notes has a new set of predefined variables.

    resources.pipeline.{Alias}.projectName 
    resources.pipeline.{Alias}.projectID 
    resources.pipeline.{Alias}.pipelineName 
    resources.pipeline.{Alias}.pipelineID 
    resources.pipeline.{Alias}.runName 
    resources.pipeline.{Alias}.runID
    resources.pipeline.{Alias}.runURI
    resources.pipeline.{Alias}.sourceBranch 
    resources.pipeline.{Alias}.sourceCommit
    resources.pipeline.{Alias}.sourceProvider 
    resources.pipeline.{Alias}.requestedFor
    resources.pipeline.{Alias}.requestedForID
    

    See here https://learn.microsoft.com/en-us/azure/devops/release-notes/2019/sprint-160-update#pipeline-resource-meta-data-as-predefined-variables