我正在尝试设置一个 azure yaml 管道,该管道使用两个部署模板来执行两个相应的作业(测试和部署)。每个阶段的作业应按顺序运行,因为测试作业会创建部署作业使用的工件。这很好用。
但是,对于一种环境,我将部署分为两个阶段,一个阶段仅运行测试,一个阶段运行实际部署。我遇到的问题是我的部署作业有一个引用测试作业的“依赖项”。因此,当我为我的环境添加这两个阶段时,我的管道无效。
我的问题是,某项工作是否存在某种动态“依赖”参考,例如“取决于此阶段之前的任何工作(如果有)”?
以下 yaml 文件中的代码片段供参考:
Main.yaml
#This first stage would work as it uses both templates in succession
stages:
- stage: BothTemplates
displayName: 'Run both templates'
jobs:
- template: TemplateTest.yml
- template: TemplateDeploy.yml #depends on the job in TemplateTest.yml
# The pipeline is invalid because of OnlyDeploy, as the TemplateDeploy.yml depends in the job "Test", which does not exist in the OnlyDeploy-context
- stage: OnlyTest
dependsOn: BothTemplates
displayName: 'Run only test template'
jobs:
- template: TemplateTest.yml
- stage: OnlyDeploy
dependsOn: OnlyTest
displayName: 'Run only deploy template'
jobs:
- template: TemplateDeploy.yml
模板测试.yaml
jobs:
- deployment: Test
dependsOn:
displayName: Test
continueOnError: false
strategy:
runOnce:
deploy:
steps:
#Here the steps for the tests are
当前TemplateDeploy.yaml
jobs:
- deployment: Deploy
dependsOn: Test
displayName: Deploy
continueOnError: false
strategy:
runOnce:
deploy:
steps:
#Here the steps for the deployment are
我的想法是将 Template Deploy.yaml 更改为如下所示:
jobs:
- deployment: Deploy
dependsOn: previousJob() #Wait until previous job in stage has finished, if there are any
displayName: Deploy
continueOnError: false
strategy:
runOnce:
deploy:
steps:
#Here the steps for the deployment are