用于持续部署触发器或工件过滤器的 DevOps YAML 构建管道多存储库触发器分支未被发布管道识别

时间:2021-05-07 11:23:21

标签: azure-devops azure-pipelines continuous-deployment azure-pipelines-release-pipeline

我有一个 YAML 构建管道,它位于存储库 PipelineRepo 的分支 master 上。

它包含对第二个存储库 AppRepo 的引用,并在分支 dev 上触发。

AppRepo/dev 上进行提交时,构建会触发并生成工件。构建期间可用的 Build.SourceBranch 预定义变量当然是 dev,因为这是 AppRepo 上的触发分支。这是根据此处的文档:

https://docs.microsoft.com/en-us/azure/devops/pipelines/repos/multi-repo-checkout?view=azure-devops#triggers

文档的具体部分是这样的:

<块引用>

当对其中一个存储库的更新触发管道时,然后 以下变量是根据触发存储库设置的:

  • Build.Repository.ID
  • Build.Repository.Name
  • Build.Repository.Provider
  • Build.Repository.Uri
  • Build.SourceBranch
  • Build.SourceBranchName
  • Build.SourceVersion
  • Build.SourceVersionMessage

我在发布管道中使用工件,在那里我有一个“开发”阶段,其中包含分支 dev 的工件过滤器:

enter image description here

我在分支 dev 的工件上有一个持续部署触发器:

enter image description here

现在我们来解决问题

每次从 AppRepo/dev 分支生成新的构建工件时,持续部署触发器都不会触发,因为它认为工件的构建分支是 PipelineRepo/master。舞台上的工件过滤器也是如此 - 我已经通过将持续部署触发器更改为 master 对其进行了测试。

注意:您可以在屏幕截图上看到构建名称包含“dev”一词。这是因为我在自定义构建名称中使用了 Build.SourceBranch 变量。这证明工件肯定是由 AppRepo/dev 触发分支产生的。

enter image description here

如何让 DevOps Release Pipeline 获取触发分支?

1 个答案:

答案 0 :(得分:1)

根据您的描述,我可以在我的组织中重现类似的问题。

当管道被另一个 repo 分支触发时,它仍然在 Release artifacts 中显示 master 分支。

同时,Pipelines 中触发器分支的显示也不一致。

例如:

概述:

enter image description here

详细视图:

enter image description here

我建议您可以在 Our feedback Site 中创建反馈票。

解决方法:

您可以在 Pipeline 中添加构建标记来区分工件。

Yaml 示例:

resources:
  repositories:
  - repository: test
    type: git
    name: 123/ARM
    trigger:
    - test

steps:
- checkout: test
- script: echo  "##vso[build.addbuildtag]$(Build.SourceBranch)" 

发布管道:

您可以设置主分支并添加构建标记。

enter image description here

相关问题