Forum Discussion

BDuffey's avatar
BDuffey
Copper Contributor
May 15, 2024

ADO YAML question re: 'enabled' and variable

- powershell: |
      write-host $(CxDebug)
    displayName: Test Debug Var
    enabled: true

 

The above code works. 

 

I'd like to leverage a pipeline variable on the last line.  When I add a variable and set it to 'true' - I get a YAML error prior to running the pipeline.

 

  - powershell: |
      write-host $(CxDebug)
    displayName: Test Debug Var
    enabled: $(CxDebug)

 

  • chamindac's avatar
    chamindac
    Brass Contributor

    BDuffey I assume you are looking to skip running the step (powershell task) based on your variable CxDebug value is false, and if it is true you want to enable the task and run it. you can achive it like below.  You can omit the enabled: true as it does not matter as we set condition.

     

    steps:
    - powershell: |
          write-host $(CxDebug)
      displayName: Test Debug Var
      condition: eq(variables['CxDebug'], 'true')
      # enabled: true

     

     

    Now when we set variable  CxDebug to true the task runs

     

    If the CxDebug is false it will skip the task.

     

     

Resources