从 Azure DevOps 中的提交哈希获取拉取请求 ID

Get the Pull request ID from commit hash in Azure DevOps

我正在尝试从构建管道页面中的提交哈希中获取拉取请求 ID(到 master 中)。这是列出 PR 中的提交消息和文件所必需的。有办法得到吗?

谢谢!

您应该能够使用预定义的构建变量调用 System.PullRequest.PullRequestId。可以找到 Azure DevOps 构建预定义变量的列表 here。文档说明

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).

以下变量也可用

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

注意:这些变量在管道模板中不可用。