azure-pipelinesazure-pipelines-build-task

Is there an env var for the build source branch of a build triggered by another build?


I have a build triggered by another build. I would like to get SourceBranchName of the build triggered the current build. Azure predefined variables offers only the following variables about the "triggered by" build:

  1. Build.TriggeredBy.BuildId
  2. Build.TriggeredBy.DefinitionId
  3. Build.TriggeredBy.DefinitionName
  4. Build.TriggeredBy.BuildNumber
  5. Build.TriggeredBy.ProjectID

And when I tried to access $(Build.TriggeredBy.SourceBranchName) I got empty string..

Any suggestions?


Solution

  • Is there an env var for the build source branch of a build triggered by another build?

    Sorry for any inconvenience.

    Just as you can see, MS provide does not provide the predefined variables about Build.TriggeredBy.SourceBranchName, so there is no such out of box env var to get the build source branch of a build triggered.

    You could add your request for this feature on our UserVoice site (https://developercommunity.visualstudio.com/content/idea/post.html?space=21 ), which is our main forum for product suggestions. Thank you for helping us build a better Azure DevOps:

    enter image description here

    As workaround, we could invoke REST API (Definitions - Update) to update the value of the triggered build definition variable in invoking pipeline task:

    PUT https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=5.0
    

    We could transfer the Build.SourceBranchName by REST API to the triggered build pipeline as a veriable, so that we could access it in the triggered build pipeline.

    You could check this thread for some more details.

    Hope this helps.