I am working on a pipeline running on a Windows Self Hosted agent. I use a script that initialize a variable in one stage and use the variable in a condition on the next two stages.
If variable is true, third stage is run, this stage as an environment with an approval.
If variable is false, fourth stage is run.
In any case, the fifth stage must always be run.
My YAML works until the fifth stage, it will run only if the fourth stage is run !!
Here is my Yaml:
stages:
- stage: Init
jobs:
- job: RunScript
steps:
- checkout: none
- task: PowerShell@2
name: compareFiles
inputs:
targetType: filePath
filePath: '***\compareFileContent.ps1'
- stage: Display1
dependsOn: Init
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
jobs:
- job: DisplayVariables
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo areFilesDifferent: $(areFilesDifferent)
- stage: WithApproval
dependsOn: Display1
condition: eq( dependencies.Init.outputs['RunScript.compareFiles.areDifferent'], 'false' )
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
jobs:
- deployment: DeploymentJob
environment: 'STWithApproval'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo DeploymentStageWithApproval: $(areFilesDifferent)
- job: SetupNext
dependsOn: DeploymentJob
steps:
- checkout: none
- task: PowerShell@2
name: setupNext
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=continue;isOutput=true]yes"
- stage: WithoutApproval
dependsOn: Display1
condition: eq( dependencies.Init.outputs['RunScript.compareFiles.areDifferent'], 'true' )
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
jobs:
- deployment: DeploymentJob
environment: 'ST'
strategy:
runOnce:
deploy:
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo DeploymentStageWithoutApproval: $(areFilesDifferent)
- job: SetupNext
dependsOn: DeploymentJob
steps:
- checkout: none
- task: PowerShell@2
name: setupNext
inputs:
targetType: 'inline'
script: |
echo "##vso[task.setvariable variable=continue;isOutput=true]yes"
- stage: Display2
condition: xor( eq( dependencies.WithApproval.outputs['SetupNext.setupNext.continue'], 'yes' ), eq( dependencies.WithoutApproval.outputs['SetupNext.setupNext.continue'], 'yes' ) )
variables:
areFilesDifferent: $[ stageDependencies.Init.RunScript.outputs['compareFiles.areDifferent'] ]
WithApproval: $[ stageDependencies.WithApproval.SetupNext.outputs['setupNext.continue'] ]
WithoutApproval: $[ stageDependencies.WithoutApproval.SetupNext.outputs['setupNext.continue'] ]
jobs:
- job: DisplayVariables
steps:
- checkout: none
- task: CmdLine@2
inputs:
script: |
echo areFilesDifferent: $(areFilesDifferent)
echo WithApproval: $(WithApproval)
echo WithoutApproval: $(WithoutApproval)
If WithApproval runs, Display2 is skipped !! ??
If WithoutApproval runs, Display2 runs but won't display the content of areFilesDifferent
I tried in Display2 to test if WithApproval or WithoutApproval ran successfully but as it wasn't working I tried setting up those 'continue' variables but it is not my favorite way of doing this.
Is it possible to branch back to Display2 after waiting for the approval ?
Thanks for any advice, Claude