Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto: Escape $(var) in Azure DevOps YAML

variables:
  buildSelected: '1.0.0.1234'

steps:
  - powershell: |
      Write-Host "Build Selected $(buildSelected)"
      Write-Host "Escaped '$(buildSelected)'"
    displayName: "Escape variable"

I would like the value 1.0.0.1234 & '$(buildSelected)' to be printed instead of what it's printing now:

Build Selected 1.0.0.1234
Escaped '1.0.0.1234'
like image 854
Vyas Bharghava Avatar asked Mar 04 '20 00:03

Vyas Bharghava


People also ask

How do I disable a task in Azure DevOps YAML pipeline?

You can try set variables : enabled = false , then use the variable in YAML file. If set this way, this task will not run in the job. This method is mentioned in this case, you can refer to it for details.

How do you escape Azure DevOps?

If you need to escape double-quotes in a string, the escape character in YAML is a backslash '\'

Are YAML parameters case sensitive?

YAML is case sensitive. YAML does not allow the use of tabs.

Is it possible to escape pipeline variables with $ (Var) in Azure DevOps?

See: Not sure if it's what you need, but escaping pipeline variables with complete $ (var) is not supported. Azure Devops will always replace it with its value if it matches the $ (var) format.

How do I use variables in Azure DevOps CLI?

Azure DevOps CLI In the most common case, you set the variables and use them within the YAML file. This allows you to track changes to the variable in your version control system. You can also define variables in the pipeline settings UI (see the Classic tab) and reference them in your YAML.

How to decrypt a secret variable in a YAML pipeline?

Secret variables are not automatically decrypted in YAML pipelines and need to be passed to your YAML file with env: or a variable at the root level. User-defined variables can be set as read-only.

How do I set variables in a YAML pipeline?

When you define a variable, you can use different syntaxes (macro, template expression, or runtime) and what syntax you use will determine where in the pipeline your variable will render. In YAML pipelines, you can set variables at the root, stage, and job level.


1 Answers

Sorry but I'm afraid Azure Devops doesn't provide the feature to escape a pipeline variable. If the variable is used in this format $(var), it will always be replaced with its value when using Write-Host to output it.

As I know in Powershell syntax, only the ` can be used to escape variables. See:

Write-Host "Build Selected `$`(buildSelected)" 

Its output : Build Selected $(buildSelected)

Not sure if it's what you need, but escaping pipeline variables with complete $(var) is not supported. Azure Devops will always replace it with its value if it matches the $(var) format.

like image 84
LoLance Avatar answered Oct 06 '22 20:10

LoLance