您如何获得给定构建的源代码库的版本?

How do you get the version for a the source repos for a given build?

我有一个管道

resources:
  repositories:

在 GUI 中,我可以获得管道 运行

时的提交哈希

我如何通过 CLI(或 REST API 如果不能在 CLI 上获得)

从控制台看来,它似乎是使用 /Contribution/HierarchyQuery

获取的

我不确定这是否可行,但我会尝试 cd 进入存储库目录,例如 $(Build.SourcesDirectory)/repo,然后我会执行 powershell 任务

- task: PowerShell@2
  displayName: get git hash ID
  inputs:
    targetType: 'inline'
    script: |
      (git log --format="%H" -n 1).substring(0,8)

您可以使用其余的 api,这不是文档:

GET https://dev.azure.com/{Organization}/{Project}/_build/results?buildId={Build ID}&__rt=fps&__ver=2

它的响应主体非常庞大,关于多个存储库的信息在:

fps -> dataProviders -> data -> ms.vss-build-web.run-details-data-provider -> repositoryResources.

详情请查看