Jobs in azure depending on jobs from other stages (inside templates)

Viewed 23

Migrating from .gitlab-ci.yml to azure-pipelines.yml. In the .gitlab-ci.yml, I havee a scenario where one job(in the deploy stage) needs two other jobs(from test stages) for its execution

.deploy
 stage: deploy
 needs:
    - testmethod1
    - testmethod2

deployPROD:
 extends: .deploy

Now here, does the deployProd job executes the testmethods again or just checks if they have been executed?

Moving to azure context, I created a templatefolder in my repository, with test file just to replicate this scenario.

My azure-pipelines.yml file is as shown below:

trigger:
- azure-pipelines

pool:
   vmImage: ubuntu-latest

jobs:
- job: InitialA
  steps:
  - script: echo hello from initial A
- job: InitialB
  steps:
  - script: echo hello from initial B
- job: Subsequent
  dependsOn:
  - templates/test1.yml/testme
  steps:
  - script: echo hello from subsequent

I used the dependsOn key to show the depending jobs. Now the structure of the repo, along with the template file, looks like this:

Show structure

But I end up getting the following error :

Error

So is my approach correct? Am I using the correct keywords in azure? if yes, what is the path that I need to consider in the dependsOnkey?

Suggestions welcome.

1 Answers

You can add a template job and the Subsequent job can dependsOn the template job. Please refer Template types & usage for more template usages in Azure Pipeline. Code sample:

trigger:
- none

pool:
  vmImage: ubuntu-latest

jobs:
- job: InitialA
  steps:
  - script: echo hello from initial A
- job: InitialB
  steps:
  - script: echo hello from initial B
- job: templates
  steps:
  - template: test.yml  # Template reference
- job: Subsequent
  dependsOn:  templates
  steps:
  - script: echo hello from subsequent
Related