我有两个合并前管道:
和一条CI / CD管道:
在用户界面存储库中,只要生成到分支main
的PR,就会运行 uipr 。 API存储库和 apipr 也是如此。
如果此PR前运行成功,则Application
管道将运行。
Application
管道将填充resources.triggeringalias
变量,其中包括执行CI的合并前管道的名称: uipr / apipr
Application
管道还具有两个布尔参数,分别称为 compileui 和 compileapi ,默认情况下设置为 false 。如果我手动运行Application
管道并将它们中的任何一个设置为true,它将执行模板以编译选择的任何一个。
我想要实现的是:
resources.triggeringalias
等于 uipr 或parameters.compileui
等于 true ,则执行模板 compileui.yaml resources.triggeringalias
等于 apipr 或parameters.compileapi
等于 true ,则执行模板 compileapi.yaml 这是我到目前为止所拥有的:
parameters:
- name: compileui
displayName: compile ui
type: boolean
default: false
- name: compileapi
displayName: compile api
type: boolean
default: false
resources:
repositories:
- repository: api
- repository: ui
pipelines:
- pipeline: ui
source: uipr
trigger: true
- pipeline: api
source: apipr
trigger: true
stages:
- stage: ci
jobs:
- job: ui
steps:
- checkout: ui
- ${{ if or(eq(variables['resources.triggerinalias'], 'ui'),eq(parameters.compileui, true)) }}:
- template: steps/build-ui.yaml
- job: api
steps:
- checkout: api
- ${{ if or(eq(variables['resources.triggeringalias'], 'api'),eq(parameters.compileapi, true)) }}:
- template: steps/build-api.yaml
我知道 (variables ['resources.triggeringalias'],'ui') 仅在运行时发生,而不在模板扩展上发生。那就是我所缺少的,不知道该怎么做
答案 0 :(得分:0)
如果得到了它,则仅当管道被另一个管道触发时或使用带标记的参数手动运行时,才希望部分管道运行。您可以这样实现:
parameters:
- name: compileui
displayName: compile ui
type: boolean
default: false
trigger: none
pr: none
resources:
pipelines:
- pipeline: hadar # Name of the pipeline resource
source: kmadof.hadar # Name of the pipeline referenced by the pipeline resource
trigger:
branches:
- releases/*
- master
stages:
- stage: printer
jobs:
- job: printVariables
steps:
- script: |
echo "$(Build.Reason)"
echo "Build run name was: $(resources.pipeline.hadar.runName)"
- ${{ if or(and(eq(parameters.compileui, true), eq(variables['build.reason'], 'Manual')), eq(variables['build.reason'], 'ResourceTrigger')) }}:
- stage: ci
condition: and(in(variables['build.reason'], 'Manual', 'ResourceTrigger'), succeeded())
jobs:
- job: ui
steps:
- script: echo "Hello from ci"
答案 1 :(得分:0)
YAML管道:如果RESOURCES_TRIGGERINGALIAS =“ ui”,则执行任务
您可以将管道资源元数据用作预定义变量resources.pipeline.<Alias>.pipelineName
,并将参数用作作业级别的条件:
- stage: ci
jobs:
- job: ui
pool:
vmImage: 'vs2017-win2016'
condition: or(eq(variables['resources.pipeline.ui.pipelineName'], 'ui'), eq(${{parameters.compileui}}, true))
steps:
- template: steps/build-ui.yaml
您可以查看以下参考资料以获取更多详细信息:
The pipeline resource metadata as predefined variables
How to get previous build pipeline's build number in case of consecutive build pipelines?