PortMan
PortMan

Reputation: 4533

How to get URL of Pipeline Build

From within a run of Azure Pipeline build, is there any way to get the URL of the build that is running?

Something like:

https://dev.azure.com/{organization}/{project}/_build/results?buildId={build_number}

I would have assumed that it would have been available as one of the environment variables, but it doesn't seem to be.

Upvotes: 10

Views: 12000

Answers (3)

mloskot
mloskot

Reputation: 38940

Here is alternative using System.CollectionUri variable which name is more generic, not specific to TFS. There is no equivalent with project name, so System.TeamProject has to be used, which will also work for GitHub repository.

The composed URL can be cached in Azure Pipelines variable in pipeline or job scope:

variables:
  MyResultsUrl: '$(System.CollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)'

Adding query parameter ?view=logs you can make the URL jump straights to the logs.

Upvotes: 7

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41755

There is no pre-defined variable of the build URL, but you can get it easily because you have a variable for the build id:

steps:
- powershell: |
   $buildUrl = "https://dev.azure.com/$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)"
   Write-Host "##vso[task.setvariable variable=buildUrl;]$buildUrl"
  displayName: 'Set build url variable'

In the next step I print the $(buildUrl) variable:

enter image description here

Upvotes: 6

Janusz Nowak
Janusz Nowak

Reputation: 2848

This one will work using all predefined variables

$buildUrl="$(System.TeamFoundationCollectionUri)$(System.TeamProject)/_build/results?buildId=$(Build.BuildId)" 

Write-Host $buildUrl

Upvotes: 18

Related Questions