Lumberjack
Lumberjack

Reputation: 549

Forking two stages back into one azure pipeline

I'm currently working on a azure devops yaml pipeline. The structure of the pipeline looks something like this: structure of yaml pipeline

As you can see I have multiple "forks" and in one case I want to bring the "forked ways" back into one. (before the download_from_source stage). The noapproval stage is kind of unnecessary and I want to delete it.

Is there a way to achieve this without having an extra stage? So it would look something like this?

new structure

Upvotes: 1

Views: 178

Answers (1)

Glue Ops
Glue Ops

Reputation: 698

Not exactly sure what you are trying to achieve but here is an example of how you can set variables in a stage and use them as conditions for future steps.

The approval check stage I assume runs some checks to validate if the pipeline should run. So if those checks pass, we can set an output variable and then use that variable to condition the download task. If the checks fail then approval=false and the download task will not run.

pipeline graphic

pool: default
variables:
  system.debug: true

stages:
  - stage: check_package
    jobs:
    - job: check_package
      steps:
        - bash: echo "checking package"

  - stage: approval_check
    jobs:
    - job: bash
      steps:
      # run some checks and if succesful we can set set output variable approved=true
        - bash: echo "##vso[task.setvariable variable=approved;isOutput=true]true"
          name: approval

  - stage: download
    dependsOn: approval_check
    condition: and(succeeded(), eq(dependencies.approval_check.outputs['bash.approval.approved'], 'true'))
    jobs:
    - job: download
      steps:
        - bash: echo "Downloading"

  - stage: download2
    dependsOn: approval_check
    condition: 
    jobs:
    - job: download
      steps:
        - bash: echo "Downloading"

Upvotes: 1

Related Questions