azure-devops - Azure Pipelines - 处理相关下游管道的构建

标签 azure-devops azure-pipelines

我们有更多数量的通用上游管道 - pipleline-a、pipleline-b、pipeline-c、pipeline-d …每个管道都有自己的存储库 -repository-a、repository-b、repository-c、repository-d… 我的目标管道(例如存储库 y 中的管道 y)依赖于这些上游管道工件,并且当任何上游库发生更改并且相应的上游管道成功构建时,需要构建目标管道。 换句话说,如果任何上游管道由于其中的更改而成功完成,则需要触发目标管道-y(上游库的 CI 触发器在其自己的管道中正常工作)。

我们目前通过使用目标 pipeline-y 中的资源管道触发器实现了这一点,如下所示:

上游管道 - pipeline-a.yml

trigger:

- repository-a*

steps

- task: Maven@3
  inputs:
  mavenPomFile: 'pom.xml'
  publishJUnitResults: false
  javaHomeOption: 'JDKVersion'
  mavenVersionOption: 'Default'
  mavenAuthenticateFeed: true
  effectivePomSkip: false
  sonarQubeRunAnalysis: false
  goals: 'package deploy'
  

目标 pipeline-y.yml 资源部分

resources:
pipelines:

- pipeline: pipeline-a
  source: pipeline-a
  trigger:
  branches:
  - 'pipeline-a-v1*'
- pipeline: pipeline-b
  source: pipeline-b
  trigger:
  branches:
  - 'pipeline-b-v1*'
- pipeline: pipeline-c
  source: pipeline-c
  trigger:
  branches:
  - 'pipeline-c-v1*'
- pipeline: pipeline-d
  source: pipeline-d
  trigger:
  branches:
  - 'pipeline-d-v1*'
- pipeline: pipeline-e
  source: pipeline-e
  trigger:
  branches:
  - 'pipeline-e-v1*'

这很好用。

我的问题是,当我们添加更多上游公共(public)库时,我们必须更新目标下游中的资源部分。当上游库有新版本时,我们必须修改resources-pipelines-pipiline-trigger中的版本 - 分支从“pipeline-a-v1”到“pipeline-a-v2”。

有更好的方法吗?可以在 resources-pipelines-pipeline-trigger - 分支 - 示例 pipeline-a-$(version) 中使用变量。可以使用构建系统变量导出版本,如下所示:

我试过了

变量: 版本:$[replace(变量['Build.SourceBranchName'], 变量['Build.Repository.Name'], '')]

好像没用。

最佳答案

无法在 YAML 中动态指定资源。

建议在添加新管道时使用 REST API Hook 。然后触发一个程序,为 pipeline-y.yml 生成新的 YAML。

关于azure-devops - Azure Pipelines - 处理相关下游管道的构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71560251/

相关文章:

powershell - 从Azure DevOps发布管道调用控制台应用程序

azure - 在 Azure YAML 管道中实现 Gates

authentication - 我可以使用带有额外 header 的 git-tfs 吗?

azure-pipelines - Azure DevOps (VSTS) 通过 YAML 链接变量组

azure - 获取日期之间或之前的成功部署

visual-studio-2012 - 将 TF.exe 与 Team Foundation Service 一起使用?

azure - 无法对 PR 验证进行排队

azure - 网关在指定时间内没有收到 'Microsoft.Sql'的响应

.net - NuGet 还原失败 - .NET 7.0 与 .NET Standard 2.0 的兼容性

Azure Pipeline - 作业取决于上一个作业,但最后一个作业是基于参数数组的循环的一部分