Handling File Paths and Special Characters in YAML for CI Pipelines
When writing YAML scripts for CI/CD pipelines, it's important to use the correct file path format and handle special characters properly. A common issue developers face is using Windows-style backslashes (\
) in paths, which YAML and many tools like Visual Studio interpret as escape characters. Another is forgetting to quote paths that contain special characters like *
.
To avoid these issues, follow these simple practices.
Use Forward Slashes Instead of Backslashes
Always use forward slashes /
in your paths. This format works on all platforms and avoids YAML parsing errors.
Instead of: {project}\publish\bin
Use:
{project}/publish/bin
Quote Paths with Special Characters
If your path includes special characters such as *
, wrap the string in double quotes. This tells YAML to treat the entire string as a literal value, not as a command or reference.
Correct usage:
"{project}/publish/bin/*"
General Tips for YAML Paths
- Use forward slashes for compatibility and readability
- Double-quote strings that include wildcards, colons, hashes, or spaces
- Avoid trailing slashes unless required by the tool
These small adjustments help make your YAML files more robust and portable.
Comments