是否可以将 git repo 标记作为变量传递给 ADO 构建管道?

Is it possible to pass in a git repo tag to an ADO build pipeline as a variable?

是否可以传入与 Azure DevOps 构建管道中的构建关联的 git 标记?

我们的标签包含正在构建和发布的软件版本,我想将该版本传递到构建过程,以便它可以包含在正在构建的代码中。

我知道 Build.BuildNumberBuild.SourceBranch 之类的东西有预定义的变量,但我希望能够定义获取与基础 [ 关联的 git 标签=19=] 构建所基于的 repo。

是的,这是可能的。您可以根据您的标签定义一个 CI 触发器。

请参考以下azure devops文档页面: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers

如您所见,您可以使用不同的选项来定义触发器以使用标签。参考下面的 YAML 定义:

trigger:
  branches:
    include:
      refs/tags/{tagname}
    exclude:
      refs/tags/{othertagname}

或者

# specific branch build
trigger:
  tags:
    include:
    - v2.*
    exclude:
    - v2.0

如果您构建的版本是一个标签(而不是 branch/commit),您可以在这两个变量中获取标签值:

Build.SourceBranch = refs/tags/test
Build.SourceBranchName = test