Azure devops 管道 - 仅在另一个管道上触发,不提交

Azure devops pipeline - trigger only on another pipeline, NOT commit

要求

因此,Azure DevOps 中有一些新功能允许管道触发其他管道并在此处记录:https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml#pipeline-triggers-1 听起来不错,除了我无法获得我需要的行为这一事实。我想在同一个存储库中使用 2 个管道:

管道 A 语法

resources:
    pipelines:
    - pipeline: database
      source: database
      trigger:
        branches:
        - develop
        - release/*
        # The stages filter should work, according to: https://docs.microsoft.com/en-us/azure/devops/pipelines/build/triggers?view=azure-devops&tabs=yaml
        # However, this error occurs when specifying: /azure-pipelines.yml (Line: 8, Col: 15): Stage filters in pipeline resource database is not supported.
        #stages:
        #- Build
    - pipeline: auth
      source: auth
      trigger:
        branches:
        - develop
        - release/*
    - pipeline: api
      source: api
      trigger:
        branches:
        - develop
        - release/*
    - pipeline: web
      source: web
      trigger:
        branches:
        - develop
        - release/*
  ... multiple triggers - 9 in total
stages:
  ...

当前行为

管道 A 不会被任何其他管道触发,而只会在其自己的存储库发生更改时触发。由于它无论如何都会更改自己的存储库,因此它会在无限循环中触发自身。

问题/评论

发现

工作解决方案

因为我的所有构建都集中在一个管道模板中,所以我更改了此模板以在成功发布工件时触发我的管道 A。这是管道触发器代码,除了最后几个步骤外,它几乎是逐字记录的(https://docs.microsoft.com/en-us/azure/devops/cli/azure-devops-cli-in-yaml?view=azure-devops):

# Updating the python version available on the linux agent
    - task: UsePythonVersion@0
      displayName: Upgrade build agent Python version
      inputs:
        versionSpec: '3.x'
        architecture: 'x64'

    # Updating pip to latest
    - script: python -m pip install --upgrade pip
      displayName: 'Upgrade pip'

    # Updating to latest Azure CLI version.
    - script: pip install --pre azure-cli --extra-index-url https://azurecliprod.blob.core.windows.net/edge
      displayName: 'Upgrade azure cli'

    - script: az --version
      displayName: 'Show Azure CLI version'

    - script: az extension add -n azure-devops
      displayName: 'Install Azure DevOps Extension'

    - script: echo ${AZURE_DEVOPS_CLI_PAT} | az devops login
      env:
        AZURE_DEVOPS_CLI_PAT: $(System.AccessToken)
      displayName: 'Login Azure DevOps Extension'

    - script: az devops configure --defaults organization=$(System.TeamFoundationCollectionUri) project="$(System.TeamProject)" --use-git-aliases true
      displayName: 'Set default Azure DevOps organization and project'

    - script: |
        set -euo pipefail
        if [[ "$(Build.SourceBranch)" == *"/release/"* ]]; then
          branchName="master"
        else
          branchName="develop"
        fi
        commandLine="--branch $branchName --name <YourPipelineName>"
        echo "Triggering release creation with: az pipelines run $commandLine"
        az pipelines run $commandLine
      displayName: Trigger release build for internal (develop) and external (release) builds

注意事项

  • 适当更改 <YourPipelineName>,您的分支名称处理将与我的不同
  • Azure CLI 升级需要 1.5 分钟,因此如果您想显着加快速度,只需删除前 3 个步骤
  • 我宁愿触发管道声明它自己的触发器,因为如果你能看到是什么导致它触发,它更容易维护,但是嘿嘿

我 运行 遇到了同样的问题。 我在这里找到了解决方案: https://developercommunity.visualstudio.com/content/problem/864701/pipeline-trigger-not-working-as-expressed-in-docum.html?childToView=897210#comment-897210

简而言之,当我将依赖管道中的 defaultBranch 更改为工作分支时 触发开始工作: 你需要去:

Edit -> Triggers (3 dots in right upper corner) -> YAML -> Get sources -> Default branch for manual and scheduled builds

在那边放置一个分支,您的 yaml 管道就在其中。

如果您不是从触发管道发布工件,它不会触发触发管道。我已经创建了一个可行的最小可行产品,并且我已经在 .

中解释了这个过程