如何仅在标记主分支时触发 azure yml 管道

时间:2021-01-29 02:45:15

标签: azure azure-devops yaml azure-pipelines

关于 azure yml 管道触发器

如何达到以下要求 我想触发我的 azure yml 管道

  • 如果 PR 合并到 master 分支,应该在 master 分支上触发管道
  • 如果在 master 分支上添加了 git 标签,应该在 master 分支上触发管道。
  • 如果在非主分支(如开发、功能分支)上添加了 git 标签,则不应触发管道
  • 如果 PR 被合并或提交发生在这些分支上,应该在非主分支上触发管道

如何处理这个任何想法,我现在有以下触发器设置?

trigger:
  branches:
    include:
    - develop
    - master
    - features/*
  paths:
    exclude:
    - README.md
    - azure-pipelines.yml
  tags:
    include:
    - refs/tags/*-RELEASE

1 个答案:

答案 0 :(得分:0)

在Azure DevOps Service中,yaml构建只是触发当前分支,比如dev分支中的.yml文件,添加Push触发器trigger - master,然后在master分支推送代码,它不会触发构建。

作为一种解决方法,我们需要更新不同分支中的 .yml 内容。

例如,如果我们在 master 分支中创建 YAML build,它将在 master 分支中创建 azure-pipelines.yml 文件。

  • 如果 PR 合并到 master 分支,应该在 master 分支上触发管道
  • 如果在 master 分支上添加了 git 标签,应该在 master 分支上触发管道。

我们可以通过添加以下推送触发器来实现

trigger:
  batch: true
  branches:
    include:
    - master
  tags:
    include:
    - refs/tags/*-RELEASE
  • 如果在非主分支(如开发、功能分支)上添加了 git 标签,则不应触发管道
  • 如果 PR 被合并或提交发生在这些分支上,应该在非主分支上触发管道

然后创建分支 develop 和 features,它也包含文件 azure-pipelines.yml,编辑文件内容。

trigger:
  batch: true
  branches:
    include:
    - develop #in the develop enter develop, in the feature branch, we need to update it to feature.
  tags:
    exclude:
    - refs/tags/*-RELEASE

更新 1

enter image description here

相关问题