Code Bug Fix: Filetransform task escapes newline during Azure pipeline task

Original Source Link

I inserted the following variable in the library

When I file transform the following string is inserted

How can I prevent this?

You can follow below steps to fix this.

1, Use a delimiter(eg, ;) instead of n to divide the new line in your multiline variable.

For example. Define your variable(eg.myVariable in below example) as mymultilinevar;containinganewline

2, Add a script task before File Transform task to replace ; with %0A (which is the hexadecimal value of n).

And update your variable(myVariable) with the replaced value. See below example scripts in powershell task:

$muline = "$(myVariable)" -replace ";", "%0A"
Write-Host "##vso[task.setvariable variable=myVariable]$($muline)"

See document Set variables in scripts about statement ##vso[task.setvariable]

3, Then run File Transfom task, the variable should be replaced with mymultilinevarncontaininganewline

enter image description here

Tagged : /

Leave a Reply

Your email address will not be published. Required fields are marked *