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 badge2 Answers
Reset to default 0No 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:
No changes in the template file
azure-build.yaml
.. . . jobs: - job: 'buildJob' steps: . . .
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: . . .
In the main YAML (
Pipeline.yaml
) of the pipeline.If you pass a job name to the parameter
dependsOn
from the main YAML intoazure-test.yaml
, thetestJob
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
, thetestJob
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条)