Reputation: 9194
I have a condition for a stage to run. The condition is true
, but the stage keeps being skipped and I'm not sure why.
This is the stage:
stages:
- stage: UnitTests
displayName: Run unit tests on service...
condition: eq(stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'], true)
dependsOn: Changed
variables:
test: $[ stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'] ]
jobs:
- job: UnitTests
displayName: Running unit tests...
steps:
- bash: |
echo $(test)
Or assigning it to a variable:
stages:
- stage: UnitTests
displayName: Run unit tests on service...
variables:
test: $[ stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'] ]
condition: eq(variables.test, true)
# dependsOn: Changed
jobs:
- job: UnitTests
displayName: Running unit tests...
steps:
- bash: |
echo $(test)
However, if I comment out the condition
and dependsOn
, sure enough the echo $(test)
does print out true
.
stages:
- stage: UnitTests
displayName: Run unit tests on service...
# condition: eq(stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'], true)
# dependsOn: Changed
variables:
test: $[ stageDependencies.Changed.Changes.outputs['detectChange.anyServicesChanged'] ]
jobs:
- job: UnitTests
displayName: Running unit tests...
steps:
- bash: |
echo $(test)
Starting: Bash
==============================================================================
Task : Bash
Description : Run a Bash script on macOS, Linux, or Windows
Version : 3.182.0
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/bash
==============================================================================
Generating script.
Script contents:
echo true
========================== Starting Command Output ===========================
/usr/bin/bash --noprofile --norc /home/vsts/work/_temp/119fb181-f890-4c1c-bffa-94142b0d51d9.sh
true
Finishing: Bash
This is the stage where changes are detected:
stages:
- stage: Changed
displayName: Checks for changes in services and configs...
jobs:
- job: Changes
displayName: Checking for changes in services and configs...
steps:
- bash: |
mapfile -t servicesChanged < <(git diff HEAD origin/production --name-only | awk -F'/' 'NF!=1{print $1}' | sort -u)
echo "Total Changed: ${#servicesChanged[@]}"
if [[ ${#servicesChanged[@]} > 0 ]]; then
echo "Any services changed: True"
echo "##vso[task.setvariable variable=anyServicesChanged;isOutput=true]true"
fi
name: detectChange
So I'm not sure what I'm doing wrong here that it keeps skipping this stage when the condition
and dependsOn
is active. Any suggestions?
Upvotes: 1
Views: 311
Reputation: 3195
When you use this condition(Stage depending on job output) on a stage, you must use the dependencies
variable, not stageDependencies
.Thus the following syntax should work.
- stage: UnitTests
displayName: Run unit tests on service...
condition: eq(dependencies.Changed.outputs['Changes.detectChange.anyServicesChanged'], true)
dependsOn: Changed
See: Stage depending on job output for details.
Upvotes: 2