Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure DevOps template as a dependency for a job

Tags:

azure-devops

I use Azure DevOps Templates in Stage and I want some job to start only when Job from template is completed (dependsOn):

- stage: stage1
  jobs:
  - job: job1
    steps:
    - bash: |
      ...

  - template: template1.yml
    parameters:
      param1: 'val1'

  - job: job2
    **dependsOn: how to put `template: template1.yml` here?**
    steps:
    - bash: |
      ...

How could it be done?

like image 471
kagarlickij Avatar asked Jan 27 '20 19:01

kagarlickij


1 Answers

Building on Eric Smith's answer you can pass in the name of the job that the template will depend on as a parameter.

#template1.yml

jobs:
- job: mytemplateJob1
  steps:
  - script: npm install
#template2.yml
parameters:
  DependsOn: []

jobs:
- job: mytemplateJob2
  dependsOn: ${{ parameters.DependsOn }}
  steps:
  - bash: pwd

By setting the default value for DependsOn to [] you ensure that the template will run if no value is passed in for DependsOn but you can optionally create a dependency like this:

stages:
- stage: stage1
  jobs:
  - template: template1.yml  # Template reference

  - template: template2.yml
    parameters:
      DependsOn: 'mytemplateJob1'
like image 158
Nick Graham Avatar answered Oct 05 '22 04:10

Nick Graham