Successfully added
DevOps
by Patrik
How to Safely Use Write-Host with Colons in YAML Scripts
When writing scripts in YAML (such as for Azure DevOps pipelines), using colons :
inside commands like Write-Host
can sometimes trigger validation warnings in tools like Visual Studio.
This happens because YAML uses colons to define key-value pairs, and it may confuse your script as malformed YAML if colons aren't properly handled.
Here's how to avoid the issue:
✔️ Recommended Solutions
1. Use multi-line block with |
Best for longer scripts or when readability matters.
steps:
- powershell: |
Write-Host "Value is: 42"
2. Quote single-line scripts
Wrap the whole command in single or double quotes.
steps:
- script: "Write-Host 'Value is: 42'"
displayName: 'Print Value'
❌ Avoid this pattern:
yaml
scripting
devops
powershell
ci/cd
Referenced in:
Comments