我有一对夫妇的作业模板的需求,但我不能得到的条件和依赖关系配置为运行我想要的方式。下面是基本的yaml:
parameters:
- name: environment
displayName: Environment
- name: action
values:
- deploy
- undeploy
- redeploy
default: redeploy
stages:
- stage: app
displayName: App
jobs:
- deployment: kickoff
environment:
name: ${{ parameters.environment }}
resourceType: virtualMachine
tags: app
strategy:
runOnce:
deploy:
steps:
- checkout: none
- powershell: Write-Host "Run kickoff tasks"
- template: undeploy.yml
parameters:
environment: ${{ parameters.environment }}
action: ${{ parameters.action }}
- template: deploy.yml
parameters:
environment: ${{ parameters.environment }}
action: ${{ parameters.action }}
我的要求如下:
- 取消。如果Action = ' Deploy ',则不运行。如果Action = ' Undeploy ',则只运行此模板。Action = ' Redeploy ',运行两个模板,但取消部署。
- 部署。如果Action = ' Deploy ',只运行这个模板。如果Action = ' Undeploy ',则不运行。如果Action = ' Redeploy ',运行两个模板,但要部署。
我能得到的最接近的是设置模板yaml如下:
undeploy.yml
parameters:
- name: environment
default: environmentToDeployTo
- name: action
values:
- deploy
- undeploy
- redeploy
default: redeploy
jobs:
- deployment: undeploy
dependsOn: kickoff
condition: ne ('${{parameters.action}}', 'deploy')
environment:
name: ${{ parameters.environment }}
resourceType: virtualMachine
tags: app
strategy:
runOnce:
deploy:
steps:
- checkout: none
#undeploy steps here#
deploy.yml
parameters:
- name: environment
default: environmentToDeployTo
- name: action
values:
- deploy
- undeploy
- redeploy
default: redeploy
jobs:
- deployment: dploy
dependsOn: undeploy
condition: ne ('${{parameters.action}}', 'undeploy')
environment:
name: ${{ parameters.environment }}
resourceType: virtualMachine
tags: app
strategy:
runOnce:
deploy:
steps:
- checkout: none
#dploy steps here#
这个结果只影响部署。但它不能单独运行-取消部署。必须事先运行Yml作业模板。但是,如果没有"dependsOn",我看不到其他方法来确保取消部署。Yml优先运行
是否有办法按照上述要求实现这一目标?
Thanks in advance
dependsOn
接受阶段或作业的名称作为输入,而不是模板文件的名称。查看更多的模板将是有用的,但是如果您可以在dependsOn中使用阶段或作业的名称,您可能会得到您正在寻找的结果。
将展开的模板视为此处的指南——您可以引用在不同模板中声明的阶段或作业,只要它在管道运行时扩展到正确的位置即可。