1

I am building a YAML pipeline in Azure DevOps. I'm generating couple of variables in first job, which I'm passing to other job and want to use them to conditionally run some steps.

Here's how the code looks like:

     stages:
      - stage: ConditionalVars
        jobs:
        - job: outputVars
          steps:
            - pwsh: |
                Write-Host "##vso[task.setvariable variable=varExample;isOutput=true]testVar"
              name: setVars
        - job: useVars
          dependsOn: outputVars
          variables:
            varFromJob: $[ dependencies.outputVars.outputs['setVars.varExample']]
          steps:
          - ${{ if eq($(varFromJob), 'testVar')}}:
            - pwsh: |
                Write-Output "Conditionally run"

I am able to print $(varFromJob) variable in step in job useVars. But I'm not able to use it in this if (condition) example.

I was trying different approaches like variables.varFromJob and other taken from https://learn.microsoft.com/en-us/azure/devops/pipelines/process/conditions?view=azure-devops&tabs=yaml.

Have you guys been struggling with similar issue? How could I define it to make it work?

Thanks a lot! Rafal

thedp
  • 8,350
  • 16
  • 53
  • 95

1 Answers1

0

Try to use a condition for the step:

steps:
   - pwsh: |
       Write-Output "Conditionally run"
     condition: eq(variables['varFromJob'], 'testVar')

${{ if eq... }} is a compile-time expression that is evaluated when the YAML file is compiled.

mm8
  • 163,881
  • 10
  • 57
  • 88