Reputation: 9194
This is what I have for this particular stage:
parameters:
- name: services
type: object
default:
- admin
- admin-v2
- api
- client
stages:
- stage: UnitTests
displayName: Run unit tests on service...
dependsOn: Changed
condition: succeeded()
variables:
apiChanged: $[ stageDependencies.Changed.Changes.outputs['detectChanges.apiChanged'] ]
jobs:
- job: UnitTests
condition: or(eq(stageDependencies.Changed.Changes.outputs['detectChanges.anyServicesChanged'], true), eq(variables['Build.Reason'], 'Manual'))
displayName: Running unit tests...
steps:
- ${{ each service in parameters.services }}:
- ${{ if and(eq(service, 'api'), eq(variables.apiChanged, true)) }}:
- bash: |
echo "Now running ${{ service }} unit tests..."
The line that is in question is:
- ${{ if and(eq(service, 'api'), eq(variables.apiChanged, true)) }}:
bash
executes when service = 'api'
.bash
does not execute which leads me to believe it comes back false
.false
.So the eq(variables.apiChanged, true)
is obviously the problem.
I have verified that apiChanged = true
by doing the following:
- bash: |
echo $(apiChanged)
I've done this before the - ${{ each service in parameters.services }}:
and it comes back true
.
I've also tried eq(variables.adminV2Changed, true)
and eq(variables.adminV2Changed, 'true'
).
Any suggestions for why this happening and how to fix it?
Upvotes: 0
Views: 349
Reputation: 5242
In Azure DevOps, the syntax ${{}}
is for compile time and $[]
is for runtime expressions. That means that when ${{}}
expressions execute, $[]
expressions have not yet executed.
In other words, in a compile-time expression, you only have access to parameters and statically defined variables.
In your case, the compile-time expression contains a variable apiChanged
which needs to be execute. Its value is $[stageDependencies.Changed.Changes.Outputs['detectChanges. ApiChanged]]
instead of the calculated value true
.
Upvotes: 1