Azure adds leading space to variable


If I run this powershell code locally:

The output is:

When I run this code on a Azure Powershell:

And then create the URL in another Azure Powershell script:

The ouput is


What’s causing this leading space character in the $env:prSourceBranchName?


Azure isn’t adding anything – your write-host is!

Your code is doing this:

but presumably you want

Note where the second quote is the write-host in both examples. In the first it’s before the $x variable name. In the second it’s after.

In your question it’s calling this (with the quote before the variable name):

which will write a logging command to the log file, and Azure DevOps will process that and update the environment variable.

You’re probably expecting it to write this to the log file:

but it’s actually writing this:

Try switching your code to this (i.e. second quote after the variable name):

and it should omit the space in front of the branch name in your url.


Azure adds leading space to variable by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply