How to set dependsOn in azure yaml template job which is referring other yaml template jobs - Stack Overflow

How to set the dependsOn in azure yaml template job which is only referring other yaml template jobs?I

How to set the dependsOn in azure yaml template job which is only referring other yaml template jobs?

I have azure devops pipeline job similar:

e.g. Pipeline.yaml


jobs: 
   - template: azure-build.yaml@templates
     parameters: 
       param1: 'A'
 
    - template: azure-test.yaml@templates
     parameters: 
       param1: 'B'

azure-build.yaml

jobs:
- job: 'buildJob'
  steps:
  task: task1..

azure-test.yaml

jobs:
- job: 'testJob'
  steps:
  task: task1..

In pipleline.yaml, how can I ensure that azure-build.yaml template job should complete before azure-test.yaml template job?

Is there any way to add dependsOn clause in pipeline.yaml template without altering azure-build.yaml and azure-test.yaml templates, which are also used by other teams in their build pipelines?

How to set the dependsOn in azure yaml template job which is only referring other yaml template jobs?

I have azure devops pipeline job similar:

e.g. Pipeline.yaml


jobs: 
   - template: azure-build.yaml@templates
     parameters: 
       param1: 'A'
 
    - template: azure-test.yaml@templates
     parameters: 
       param1: 'B'

azure-build.yaml

jobs:
- job: 'buildJob'
  steps:
  task: task1..

azure-test.yaml

jobs:
- job: 'testJob'
  steps:
  task: task1..

In pipleline.yaml, how can I ensure that azure-build.yaml template job should complete before azure-test.yaml template job?

Is there any way to add dependsOn clause in pipeline.yaml template without altering azure-build.yaml and azure-test.yaml templates, which are also used by other teams in their build pipelines?

Share Improve this question asked Mar 6 at 7:13 Tanu GTanu G 11 bronze badge
Add a comment  | 

2 Answers 2

Reset to default 0

No way can let the testJob depend on buildJob without changing the template file azure-test.yaml.

For your case you can make changes like as below:

  1. No changes in the template file azure-build.yaml.

    . . .
    
    jobs:
    - job: 'buildJob'
      steps:
      . . .
    
  2. Update the template file azure-test.yaml like as below.

    parameters:
    - name: dependsOn
      type: string
      default: ''
    . . .
    
    jobs:
    - job: testJob
      ${{ if ne(parameters.dependsOn, '') }}:
        dependsOn: ${{ parameters.dependsOn }}
      steps:
      . . .
    
  3. In the main YAML (Pipeline.yaml) of the pipeline.

    • If you pass a job name to the parameter dependsOn from the main YAML into azure-test.yaml, the testJob will depend on that job.

      resources:
        repositories:
        - repository: templates
          . . .
      
      jobs:
      - template: azure-build.yaml@templates
      
      - template: azure-test.yaml@templates
        parameters:
          dependsOn: buildJob  # Set to depend on buildJob.
      
    • If you do not pass any value to the parameter dependsOn, the testJob will not depend on any job.

      . . .
      
      jobs:
      - template: azure-build.yaml@templates
      
      - template: azure-test.yaml@templates
      

I added the stages: to main pipeline and moved the job templates inside stage: statements. Added DependsOn to stage:.

This changes in pipeline.yaml file avoided change in azure-build.yaml file and solved my purpose to add dependency between two jobs.

e.g.

Pipeline.yaml

stages: 
  - stage: 'build'      
    jobs:
    - template: azure-build.yaml@templates
      parameters:
      ...
  - stage: 'test'
    dependsOn: 'build'
    jobs:
    - template: azure-test.yaml@templates
      parameters:
      ...
  

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744992464a4604987.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信