繁体   English   中英

能否在 Azure DevOps 中触发 CD 管道之前组合多个 CI 构建?

[英]Can you combine multiple CI builds prior to a CD pipeline being triggered in Azure DevOps?

我们有 2 个 CI 构建,一个用于数据库,一个用于 Dotnet。 当向主分支提交相应目录(即 /database 或 /dotnet)时,会触发这些。

在 CI 构建的背后,会触发一个 CD 管道来实际部署新资源。

我遇到的问题是,如果我将 PR 合并到对/database/dotnet都有更改的 master 中,则会触发 2 个 CI 构建(正确),但随后我也会得到 2 个 CD 部署(不正确!)。 我试图找出一种方法,它会等待两个 CI 构建,因为它们在同一个提交中,然后触发 CD 管道。

有谁知道这可能吗?

以下是精简代码的示例文件。

文件结构:

├── CI-Database.yml
├── CI-Dotnet.yml
├── CD-Pipeline.yml
├── database
│   └── adatabasefile.sql
├── deploy-env.yml
└── dotnet
    └── adotnetfile.cs

CI-数据库.yml

trigger:
  branches:
    include:
    - main
    - releases/*
  paths:
    include:
    - database

name: $(Build.DefinitionName)_$(Date:yyyyMMdd)$(Rev:.r)_$(SourceBranchName)

pool:
  vmImage: 'ubuntu-latest'

steps:
  - script: echo 'Hello from database'

  - publish: '$(Build.SourcesDirectory)/database'
    artifact: 'the-database'

CI-Dotnet.yml

trigger:
  branches:
    include:
    - main
    - releases/*
  paths:
    include:
    - dotnet

name: $(Build.DefinitionName)_$(Date:yyyyMMdd)$(Rev:.r)_$(SourceBranchName)

pool:
  vmImage: 'ubuntu-latest'

steps:
  - script: echo 'Hello from dotnet pipeline'

  - publish: '$(Build.SourcesDirectory)/dotnet'
    artifact: 'the-dotnet'

CD-Pipeline.yml

trigger:
  branches:
    include:
    - main
  paths:
    include:
    - infrastructure

pool:
  vmImage: 'ubuntu-latest'

resources:
  pipelines:
  - pipeline: databasepipeline
    source: CI-Database
    trigger: 
      branches:
        include: 
        - main
  - pipeline: dotnetpipeline
    source: CI-Dotnet
    trigger: 
      branches:
        include: 
        - main

stages:
- stage: DeployDEV
  displayName: 'DEV Deploy'
  jobs:
    - job: 
      steps: 
        - pwsh: Write-Host "Deploy the consumed CI resources here"

否。多个资源触发器是不是 这是已实现的行为,无法更改它。 你唯一能改变的就是你的过程。

一般来说,没有理由为构建和部署使用单独的管道。 您可以使用dependsOn关系和条件阶段将单个管道分解为多个作业。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM