【问题标题】:Azure DevOps Pipeline double triggered when using branch policies and build validation使用分支策略和生成验证时 Azure DevOps Pipeline 双触发
【发布时间】:2021-06-10 00:43:26
【问题描述】:

由于 Azure DevOps Pipelines 不为 Azure Repos 触发 PR,因此您应该使用 Branch Policies

我已经设置好了,所以你必须打开一个 PR 才能合并到 production,而你不能直接推送到 production

我还在 PR 中添加了 Build Validation。应该做的是,一旦 PR 被创建,它将(最终......小步骤)构建、运行单元测试、集成测试等。如果它们通过,则在 PR 清单中检查该部分,最终它可以是批准到production 并部署到 Kubernetes。

无论如何,我遇到的问题是如何设置azure-pipelines.yaml。当前发生的情况是,一旦将短期分支推送到远程 (git push origin test-branch),它就会触发管道,然后在创建 PR 请求时再次触发它。我只希望它在创建 PR 时运行,我没有看到如何设置 azure-pipelines.yaml 来执行此操作。

这是我正在测试的:

trigger:
  branches:
    exclude:
    - production
  paths:
    include:
    - admin
    - admin-v2
    - api
    - client
    - k8s
    - templates
    - azure-pipelines.yaml

resources:
- repo: self

variables:

  # Container registry service connection established during pipeline creation
  dockerRegistryServiceConnection: '<GUID>'
  imageRepository: 'apptest'
  containerRegistry: 'apptestacr.azurecr.io'
  dockerfilePath: '$(Build.SourcesDirectory)'
  tag: '$(Build.BuildId)'
  imagePullSecret: 'apptestacr8a25-auth'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Changes
  jobs:
  - job: Changes
    steps:
    - bash: |
        changedServices=$(git diff $(git branch --show-current) production --name-only | awk -F'/' 'NF!=1{print $1}' | sort -u)
        echo $changedServices

很容易看出为什么它会在git push 上触发:它正在查看除production 之外的每个分支。我还尝试完全删除 trigger 部分,它仍然做同样的事情。

这是构建验证设置的内容:

我应该如何设置它来完成这个功能(只在 PR 上触发构建验证)?

【问题讨论】:

    标签: azure azure-devops azure-pipelines build-pipeline


    【解决方案1】:

    好的,看起来下面的工作完成了:

    trigger: none
    

    上面的文档:Opting out of CI.

    当我将更改推送到 repo 时它没有触发,但在我打开 PR 时触发。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-06
      • 2020-12-23
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多