Get the Pull request ID from commit hash in Azure DevOps

Viewed 622

I am trying to get the Pull request ID (into master) from the commit hash in the build pipeline page. This is needed to list the commit messages and files inside the PR. Is there a way to get it ?

Thanks!

1 Answers

You should be able to use the predefined build variable call System.PullRequest.PullRequestId. A list of Azure DevOps build predefined variables can be found here. The documentation states

The ID of the pull request that caused this build. For example: 17. (This variable is initialized only if the build ran because of a Git PR affected by a branch policy).

The following variables are also available

  • System.PullRequest.PullRequestNumber
  • System.PullRequest.SourceBranch
  • System.PullRequest.SourceRepositoryURI
  • System.PullRequest.TargetBranch

Note: These variables are not available in pipeline templates.

Related