Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Azure DevOps Pipelines Stage Dependency Variables Usage Demo
parameters:
- name: Value
type: boolean
default: true
pool:
vmImage: ubuntu-latest
stages:
- stage: SetupStage
displayName: 'Setup Stage'
jobs:
- job: SetupJob
displayName: 'Setup Job'
steps:
- checkout: none
- bash: |
set -e # need to avoid trailing " being added to the variable https://github.com/microsoft/azure-pipelines-tasks/issues/10331
echo "##vso[task.setvariable variable=MyVar;isOutput=true]${{parameters.value}}"
name: SetupStep
displayName: 'Setup Step'
- stage: Dummy_Stage
jobs:
- job: DummyJob
steps:
- bash: echo "A dummy stage"
- stage: Show_No_Dependancy
displayName: 'Show Stage no dependancy'
variables:
localMyVarViaStageDependancies : $[stageDependencies.SetupStage.SetupJob.outputs['SetupStep.MyVar']]
localMyVarViaDependancies : $[dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar']]
jobs:
- job: Job
displayName: 'Show Job no dependancy'
steps:
- bash: |
echo "localMyVarViaStageDependancies - $(localMyVarViaStageDependancies)"
echo "localMyVarViaDependancies - $(localMyVarViaDependancies)"
# echo "StageDependancies - $[stageDependencies.SetupStage.SetupJob.outputs['SetupStep.MyVar']]"
# echo "Dependancies - $[dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar']]"
- stage: Show_No_Dependancy_Condition
condition: and (succeeded(), eq (dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar'], 'True'))
displayName: 'Show Stage no dependancy'
jobs:
- job: Job
displayName: 'Show Job no dependancy'
steps:
- bash: echo "I ran based on stage condition"
- stage: Show_With_Dependancy
displayName: 'Show Stage With dependancy'
dependsOn:
- SetupStage
variables:
localMyVarViaStageDependancies : $[stageDependencies.SetupStage.SetupJob.outputs['SetupStep.MyVar']]
localMyVarViaDependancies : $[dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar']]
jobs:
- job: Job
displayName: 'Show Job With dependancy'
steps:
- bash: |
echo "localMyVarViaStageDependancies - $(localMyVarViaStageDependancies)"
echo "localMyVarViaDependancies - $(localMyVarViaDependancies)"
# echo "StageDependancies - $[stageDependencies.SetupStage.SetupJob.outputs['SetupStep.MyVar']]"
# echo "Dependancies - $[dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar']]"
- job: waitForValidation
displayName: Wait for external validation
pool: server
timeoutInMinutes: 4320 # job times out in 3 days
steps:
- task: ManualValidation@0
timeoutInMinutes: 1 # task times out in 1 minute
inputs:
notifyUsers: |
bm-richard.fennell@outlook.com
instructions: 'localMyVarViaStageDependancies - $(localMyVarViaStageDependancies)'
onTimeout: 'resume'
- stage: Show_With_Dependancy_Condition
condition: and (succeeded(), eq (dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar'], 'True'))
displayName: 'Show Stage With dependancy Condition'
dependsOn:
- SetupStage
variables:
localMyVarViaStageDependancies : $[stageDependencies.SetupStage.SetupJob.outputs['SetupStep.MyVar']]
localMyVarViaDependancies : $[dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar']]
jobs:
- job: Job
displayName: 'Show Job With dependancy'
steps:
- bash: |
echo "localMyVarViaStageDependancies - $(localMyVarViaStageDependancies)"
echo "localMyVarViaDependancies - $(localMyVarViaDependancies)"
# echo "StageDependancies - $[stageDependencies.SetupStage.SetupJob.outputs['SetupStep.MyVar']]"
# echo "Dependancies - $[dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar']]"
- job: waitForValidation
displayName: Wait for external validation
pool: server
timeoutInMinutes: 4320 # job times out in 3 days
steps:
- task: ManualValidation@0
timeoutInMinutes: 1 # task times out in 1 minute
inputs:
notifyUsers: |
bm-richard.fennell@outlook.com
instructions: 'localMyVarViaStageDependancies - $(localMyVarViaStageDependancies)'
onTimeout: 'resume'
- stage: Post_Show_With_Dependancy_Condition
dependsOn:
- Show_With_Dependancy_Condition
jobs:
- job: DummyJob
steps:
- bash: echo "A dummy stage"
- stage: Post_Show_With_Dependancy_Condition_Handle_Skip
condition: and( not(failed()), not(canceled()))
dependsOn:
- Show_With_Dependancy_Condition
jobs:
- job: DummyJob
steps:
- bash: echo "A dummy stage"
- stage: Show_With_Dependancy_Condition_Job
displayName: 'Show Stage With dependancy Condition'
dependsOn:
- SetupStage
variables:
localMyVarViaStageDependancies : $[stageDependencies.SetupStage.SetupJob.outputs['SetupStep.MyVar']]
localMyVarViaDependancies : $[dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar']]
jobs:
- job: Job
condition: and (succeeded(),
eq (variables.localMyVarViaStageDependancies, 'True'))
displayName: 'Show Job With dependancy'
steps:
- bash: |
echo "localMyVarViaStageDependancies - $(localMyVarViaStageDependancies)"
echo "localMyVarViaDependancies - $(localMyVarViaDependancies)"
# echo "StageDependancies - $[stageDependencies.SetupStage.SetupJob.outputs['SetupStep.MyVar']]"
# echo "Dependancies - $[dependencies.SetupStage.outputs['SetupJob.SetupStep.MyVar']]"
- job: waitForValidation
condition: and (succeeded(),
eq (variables.localMyVarViaStageDependancies, 'True'))
displayName: Wait for external validation
pool: server
timeoutInMinutes: 4320 # job times out in 3 days
steps:
- task: ManualValidation@0
timeoutInMinutes: 1 # task times out in 1 minute
inputs:
notifyUsers: |
bm-richard.fennell@outlook.com
instructions: 'localMyVarViaStageDependancies - $(localMyVarViaStageDependancies)'
onTimeout: 'resume'
- stage: Post_Show_With_Dependancy_Condition_Job
dependsOn:
- Show_With_Dependancy_Condition_Job
jobs:
- job: DummyJob
steps:
- bash: echo "A dummy stage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment