0

I am using Azure pipelines variables to construct a set of parameters for a command. The type of variable I must use for Azure pipelines is in macro format (like $(var)), you can see the details of it here: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/variables?view=azure-devops&tabs=yaml%2Cbatch#runtime-expression-syntax

If $(var) does not contain a value, instead of printing "nothing", it will print $(var)

When I run my command and that value isn't passed in, an error prompts on the screen that command was not found. At the moment it's not a big deal, it doesn't error my following set of commands, but I was hoping to suppress it at the very least.

VAR_TERRAFORMDESTROY="$(TERRAFORMDESTROY)"

if [ ${#VAR_TERRAFORMDESTROY} -ge 1 ]; then
  VAR_TERRAFORMDESTROY="yes"
else
  VAR_TERRAFORMDESTROY="no"
fi

In the logs output it will print /vsts/_work/_temp/4e426335-0930-4375-b05c-c4dbbcb38139.sh: line 5: TERRAFORMDESTROY: command not found

I have tried VAR_TERRAFORMDESTROY="$(TERRAFORMDESTROY)" > /dev/null 2>&1, but because > /dev/null 2>&1 is not inside the brackets (), it will not output the result to null. And it cannot be inside the brackets due to how Azure YAML variables work.

Can anyone suggest anything to suppress the command not found output for me, please?

Beefcake
  • 733
  • 2
  • 12
  • 37
  • What about just `VAR_TERRAFORMDESTROY='$(TERRAFORMDESTROY)'` followed by `if [[ VAR_TERRAFORMDESTROY = '$(''TERRAFORMDESTROY'')'' ]]; then VAR_TERRAFORMDESTROY="nothing"; fi` ? – KamilCuk Oct 19 '20 at 12:58

1 Answers1

1

Can anyone suggest anything to suppress the command not found output for me, please?

Suppress the group error message

{ VAR_TERRAFORMDESTROY="$(TERRAFORMDESTROY)"; } > /dev/null 2>&1
KamilCuk
  • 120,984
  • 8
  • 59
  • 111