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'
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.
If you need to escape double-quotes in a string, the escape character in YAML is a backslash '\'
YAML is case sensitive. YAML does not allow the use of tabs.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With