配置触发器失败,需要再次编辑并保存管道,但没有明显的错误和更多细节。

20
在将一堆YAML管道转换为使用模板来保存作业逻辑以及定义管道变量后,我遇到了一个奇怪的问题。这些管道可以完美地运行,但是在管道摘要页面的顶部会出现“检测到与管道触发器相关的一些最近问题”的警告,并且查看详细信息只会显示:“配置触发器失败,请编辑并重新保存管道。”
奇怪的是,管道完全正常工作,包括触发器。没有任何故障,也没有关于所谓问题的进一步细节。目前,我已经为管道覆盖了YAML触发器,但我还定义了相同的触发器,以查看是否有帮助(实际上并没有)。
我正在寻找任何可能导致此问题的想法,或者如何进一步排除故障,因为错误/警告提供的详细信息非常缺乏,这使得开发人员认为他们的构建可能存在问题。
以下是主要管道。构建存储库是用于保存在构建系统中多个存储库中使用的代码的共享存储库。dev.yaml包含特定于开发环境的变量值。Shared存储条件设置的变量,这些变量基于管道正在运行的分支。
name: ProductName_$(BranchNameLower)_dev_$(MajorVersion)_$(MinorVersion)_$(BuildVersion)_$(Build.BuildId)
resources:
  repositories:
    - repository: self
    - repository: build
      type: git
      name: Build
      ref: master

# This trigger isn't used yet, but we want it defined for later.
trigger: 
  batch: true
  branches:
    include: 
    - 'dev'

variables:
- template: YAML/variables/shared.yaml@build
- template: YAML/variables/dev.yaml@build

jobs:
- template: ProductNameDevJob.yaml
  parameters:
    pipelinePool: ${{ variables.PipelinePool }}
    validRef: ${{ variables.ValidRef }}

这是实际工作yaml的开始。它提供了一个可重复使用的工作定义,可以在多个总体管道中使用:

parameters:
- name: dependsOn
  type: object
  default: {}
- name: pipelinePool
  default: ''
- name: validRef
  default: ''
- name: noCI
  type: boolean
  default: false
- name: updateBeforeRun
  type: boolean
  default: false

jobs:
- job: Build_ProductName
  displayName: 'Build ProductName'
  pool:
    name: ${{ parameters.pipelinePool }}
    demands: 
    - msbuild
    - visualstudio
  dependsOn: 
  - ${{ each dependsOnThis in parameters.dependsOn }}:
    - ${{ dependsOnThis }}
  condition: and(succeeded(), eq(variables['Build.SourceBranch'], variables['ValidRef']))

  steps:
**step logic here

最后,我们有一个名为YAML的变量,它根据我们正在构建的内容有条件地设置管道变量。
variables:
- ${{ if or(eq(variables['Build.SourceBranch'], 'refs/heads/dev'), eq(variables['Build.SourceBranch'], 'refs/heads/users/ahenderson/azure_devops_build')) }}:
  - name: BranchName
    value: Dev
** Continue with rest of pipeline variables and settings of each value for each different context.
6个回答

12
你可以在这里查看我的帖子: Azure DevOps pipeline trigger issue message not going away 从你的YAML文件中可以看到,你正在使用这个分支: 'refs/heads/users/ahenderson/azure_devops_build'。
我认为你引用的一些YAML文件在你构建中定义为默认分支的分支中已经不存在了: enter image description here 切换到你的分支。

那不是正在使用的分支。那只是一个可能被使用的分支。默认分支是dev,包含所有文件和变量定义。问题在于,在评估这个逻辑时,它实际上并没有使用任何分支名称,这就是为什么需要一组默认的变量值的原因。 - AJ Henderson
2
这解决了我的问题。我使用了一个带有yaml的次要分支,而主分支(默认)没有,所以一直出现这个错误。谢谢Christophe。 - Bino
1
这也是我的问题。我已经在YAML中删除了Master触发器,但在UI中仍将主分支作为我的源分支。感谢你的帮助! - Urk

5
我想我可能已经找出问题了。似乎这与变量设置中的条件有关。在任何有效的触发器配置中,变量将被设置,但验证过程中似乎没有使用正确的值,可能导致问题。 将我的条件变量首先设置为默认值,然后再根据条件替换该值,似乎已解决了问题。
如果Microsoft能提供更有用的错误消息,例如某些变量未找到给定变量的值,那就太好了,但添加默认值似乎已经解决了问题。

4
你能给我们展示一下解决问题后更新的流程图吗?顺便说一句,谢谢。 - Kaylee Paez

2
对我来说,引起问题的是这个...
以下的pipeline.yaml会导致错误"配置触发器失败,请编辑并重新保存管道"。它与环境名称name: FeatureVMs.${{ variables.resourceName }}有关,如果我用其他内容替换${{ variables.resourceName }},例如FeatureVMs.develop,那么就不会出现错误。奇怪的是,如果我一次保存所有我想要的触发器和一个有效的环境FeatureVMs.develop,那么它会保存触发器,如果我然后将其更改为实际想要的动态环境资源选择FeatureVMs.${{ variables.resourceName }},则会出现错误,但Azure DevOps中的流水线按照我预期的工作。因此,解决方法是先不带变量保存,然后再使用变量保存所需的触发器,并接受管道顶部的错误。
这会导致错误。
trigger: none

variables:
- name: resourceName
  value: $(Build.SourceBranchName)
- name: sourcePipeline
  value: vetsxl-ci

resources:
  pipelines:
    - pipeline: vetsxl-ci
      source: vetsxl-ci
      trigger:
        branches: 
          include: 
            - develop
            - feature/F*
            - release/*
            - review/*
            - demo/*
            - hotfix/H*
            - tests/*
            - test/*

stages:
- stage: Deploy
  displayName: 'Deploy'
  condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
  jobs:
  - deployment: DeployVM
    displayName: 'Deploy to develop VM'
    environment:
      name: FeatureVMs.${{ variables.resourceName }}
    strategy:
      rolling:
        deploy:
          steps:
          - template: deploy.yml
            parameters:
              sourcePipeline: ${{ variables.sourcePipeline }}

这个运行没有任何错误。

trigger: none

variables:
- name: resourceName
  value: $(Build.SourceBranchName)
- name: sourcePipeline
  value: vetsxl-ci

resources:
  pipelines:
    - pipeline: vetsxl-ci
      source: vetsxl-ci
      trigger:
        branches: 
          include: 
            - develop
            - feature/F*
            - release/*
            - review/*
            - demo/*
            - hotfix/H*
            - tests/*
            - test/*

stages:
- stage: Deploy
  displayName: 'Deploy'
  condition: and(succeeded(), ne(variables['Build.Reason'], 'PullRequest'))
  jobs:
  - deployment: DeployVM
    displayName: 'Deploy to develop VM'
    environment:
      name: FeatureVMs.develop
    strategy:
      rolling:
        deploy:
          steps:
          - template: deploy.yml
            parameters:
              sourcePipeline: ${{ variables.sourcePipeline }}

1

在我们的情况下,出现错误是因为YAML文件的路径以斜杠开头:/builds/build.yaml

去掉斜杠就可以解决错误:builds/build.yaml


有趣的是,对我来说情况恰好相反。添加一个前导斜杠消除了错误信息。 - Gustaf Carleson

1
在我的情况下,我添加了"schedules"条目,并错误地添加了一个用于包括LIST分支的条目。
schedules:
- cron: '*/10 * * * *' # Run every 10th minutes
  displayName: Daily build no cache
  branches:
    include: refs/heads/feature/19935 # WRONG => This must be a list

更正:

schedules:
- cron: '*/10 * * * *' # Run every 10th minutes
  displayName: Daily build no cache
  branches:
    include: 
    - refs/heads/feature/19935 # This is a list now

1
在我的情况下,我已经在yaml文件中替换了触发器。然后管道就不知道从哪里开始了。
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
  - "main"  # <-- That was name wrong

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接