4

I'm trying to find a way to list all the variables defined in an Azure Devops pipeline. I've found examples using env in a script but that gets all environment variables and any defined in my yaml have their names changed (to upper case and _ instead of .)

What I'd like is just the variables dictionary output. I've tried

- ${{ each value in variables }}:
  - script: echo ${{ value.key }} ${{value.value}}  

But that makes one CmdLine task for each variable rather than just echoing them all in one task to make it easy to read

MrPurpleStreak
  • 1,477
  • 3
  • 17
  • 28

1 Answers1

0

This answer to a quite similar question might be useful for you: https://stackoverflow.com/a/69805202/13760443

According to YK1 (author of the answer), you can try

- script: |
  for var in $(compgen -e); do
     echo $var ${!var};
  done

This script will list all variables.

For example, if you use the next code (to set the pipeline's output variable):

- script: |
    echo "Checking if terraform plan has changes..."
    if [ -f tfplan ]; then export tfplan_exists=true; else export tfplan_exists=false; fi
    echo "##vso[task.setvariable variable=do_terraform_apply;isOutput=true]$tfplan_exists"
  name: validation_variable

The first script will end up printing all env variables including VALIDATION_VARIABLE_DO_TERRAFORM_APPLY