gpt4 book ai didi

azure-pipelines - 我应该如何在另一个管道的末端触发一个管道?使用 msdocs 中的示例会导致 "pipeline resource input must be valid"错误

转载 作者:行者123 更新时间:2023-12-05 05:00:39 25 4
gpt4 key购买 nike

无法在其他管道完成后触发管道

原创

我正在尝试在 devops yaml 管道中为我们的角度应用程序构建多个发布管道。我们正在使用 Nx 工作区,因此能够在工作区构建结束时触发这些管道非常重要。

这是微软提供的示例文档代码(https://learn.microsoft.com/en-us/azure/devops/pipelines/process/pipeline-triggers?view=azure-devops&tabs=yaml)

# this is being defined in app-ci pipeline
resources:
pipelines:
- pipeline: securitylib # Name of the pipeline resource
source: security-lib-ci # Name of the triggering pipeline
trigger:
branches:
- releases/*
- master

这是我此时的完整管道:

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
trigger: none

resources:
pipelines:
- pipeline: WorkspaceBuild
source: OtherPipeline
project: CommonProject
trigger:
branches:
- master
pool:
vmImage: 'ubuntu-latest'

steps:

- task: DownloadBuildArtifacts@0
inputs:
buildType: 'current'
downloadType: 'single'
artifactName: 'web-framework'
downloadPath: '$(System.ArtifactsDirectory)'

- script: |
cd $(System.ArtifactsDirectory)
dir .
displayName: 'Run a one-line script'

- script: |
echo Add other tasks to build, test, and deploy your project.
echo See https://aka.ms/yaml
displayName: 'Run a multi-line script'

更新

好的,修复命名允许每个管道运行。但是,构建管道仍然不会触发部署管道。

Respective Pipelines (UPS1_Workspace build, wf-stg deploys)

Deployment pipeline resources tag

Deployment pipeline triggers settings

更新2

嘿,这还是不行。我从触发器 ui 面板中删除了所有 CI 设置,并确保未勾选覆盖框。这里有一些更多的图像来帮助诊断

Pipeline Status's

Triggering Pipeline Step Results

Start of triggered pipeline's yml file

最佳答案

刚刚解决了这个错误Pipeline resource pipelinename must be valid - 它实际上意味着给定的source: pipeline name is invalid .

2021 年 AzureDevOps 上似乎没有 UI - 全是 YAML,这让事情变得更简单。

假设两个存储库在同一个高级项目分组中:

  1. 上游存储库有一个具有任意名称的管道(源管道)- 假设它被命名为 My Upstream Pipeline (release)。此存储库或其管道中不需要特殊配置。

  2. 下游存储库有一个管道,您希望在上游在任何“release/”分支上成功构建后触发该管道。您将以下咒语添加到它的 yaml 中:

resources:
pipelines:
- pipeline: alias_name
source: 'My Upstream Pipeline (release)'
trigger:
branches:
- release/*

如果你打错“我的上游管道(发布)”那么你会得到错误管道资源 alias_name 必须有效

将构建的下游存储库的分支是默认分支 - 我认为除了更改默认分支之外没有任何方法可以改变它。

如果您需要根据触发管道的身份在下游管道中进行任何额外处理(例如,将已发布的工件向下传递),我建议选择 alias_name 来匹配上游存储库的名称,也使用在环境变量中合法的字符。这是因为 ADO 通过许多环境变量将有关上游触发项目的信息提供给下游管道,其中 alias_name 作为这些变量名称的一部分:

  • RESOURCES_TRIGGERINGALIAS = 别名

然后将以下变量的 alias_name 大写为 ALIAS_NAME:

  • RESOURCES_PIPELINE_ALIAS_NAME_PROJECTID - 上游项目 ID
  • RESOURCES_PIPELINE_ALIAS_NAME_PIPELINEID - 上游管道 ID
  • RESOURCES_PIPELINE_ALIAS_NAME_RUNID - 上游构建或运行 ID

然后您可以构造上游(触发)管道的 URL:PIPELINEURL="${SYSTEM_TEAMFOUNDATIONSERVERURI}${RESOURCES_PIPELINE_ALIAS_NAME_PROJECTID}/_build?buildId=${RESOURCES_PIPELINE_ALIAS_NAME_RUNID}"

并使用

从中获取已发布的工件
          - task: DownloadPipelineArtifact@2
name: DownloadFromUpstream
displayName: 'Download file from upstream'
condition: eq(variables['Build.Reason'], 'ResourceTrigger')
inputs:
source: specific
project: $(RESOURCES_PIPELINE_ALIAS_NAME_PROJECTID)
pipeline: $(RESOURCES_PIPELINE_ALIAS_NAME_PIPELINEID)
runId: $(RESOURCES_PIPELINE_ALIAS_NAME_RUNID)
preferTriggeringPipeline: true
artifact: 'published-artifact-name'
path: .

引用:

  1. https://learn.microsoft.com/en-us/azure/devops/pipelines/process/pipeline-triggers
  2. https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=azure-devops&tabs=schema%2Cparameter-schema#the-pipeline-resource-metadata-as-predefined-variables

关于azure-pipelines - 我应该如何在另一个管道的末端触发一个管道?使用 msdocs 中的示例会导致 "pipeline resource input must be valid"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63019825/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com