I am trying to set up an azure yaml pipeline that uses two deployment templates for two respective jobs (test and deploy). The jobs should be run in sequence for each stage, as the test-job creates an artifact that the deploy-job consumes. This works nicely.
However, for one environment I have split the deployment into two stages, one stage that only runs tests and one stage that runs the actual deployment. The problem I run into is that my deploy-job has a "dependson" which references the test-job. Because of this, my pipeline is invalid when I add the these two stages for my environment.
My question is if there is some sort of dynamic "dependson" reference for a job, something like "depends on any previous jobs in this stage, if there are any"?
Snippets of code from the yaml-files below for reference:
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
TemplateTest.yaml
jobs:
- deployment: Test
dependsOn:
displayName: Test
continueOnError: false
strategy:
runOnce:
deploy:
steps:
#Here the steps for the tests are
Current TemplateDeploy.yaml
jobs:
- deployment: Deploy
dependsOn: Test
displayName: Deploy
continueOnError: false
strategy:
runOnce:
deploy:
steps:
#Here the steps for the deployment are
My idea would be to change TemplateDeploy.yaml to something like this:
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