Search code examples
azure-devopsazure-pipelinesazure-cliazure-pipelines-yamlazure-pipelines-tasks

In Azure DevOps bash task env, What is the variables default value if the variable doesn't exist in ADO variable group?


My question is an extension to this question: How to add env vars into Azure Devops pipeline

@Krzysztof Madej answer is correct, but I want to know if the secret env var that you're passing isn't defined in the variable group yet, what does it default to?

        - task: Bash@3
            displayName: Running bash step
            inputs:
              targetType: "inline"
              workingDirectory: "xxx"
              script: |
                az login --identity --username $(ARM_CLIENT_ID)
            env:
              ARM_CLIENT_ID: $(ARM_CLIENT_ID)

In my case, if I forgot to set ARM_CLIENT_ID in the ADO variable group, what is the default value in the pipeline going to be?

Standard expectation is an empty string or null value. But I'm seeing the bahaviour that the default is actually the literal string of the variable name ie. "$(ARM_CLIENT_ID)" in this case.

I haven't been able to find documentation at that level of detail. Has anyone come across this?

This is the closest I found https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/reference/bash-v3?view=azure-pipelines#examples


Solution

  • It works that it tries to replace literals with values assigned to variable. If there is no variable with used literal, there is no default value. It just doesn't replace that literal, and use it as string. In this way it is easier actually to debug and find missing value. If that literal would be replaced by null or empty string it could cause more harm than good. In some cases that could be valid value, and even if not in your case it would (probably) more problematic to figuring out.