0

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)) }}:
  • If it is just the first condition, the subsequent bash executes when service = 'api'.
  • If it is just the second condition, the subsequent bash does not execute which leads me to believe it comes back false.
  • Thus, having both conditions it evaluates to 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?

cjones
  • 8,384
  • 17
  • 81
  • 175

1 Answers1

1

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.

Jane Ma-MSFT
  • 4,461
  • 1
  • 6
  • 12