Reputation: 3687
I'm using a pipeline template and have a few string runtime parameters that will be file systems paths and they contain backslashes, I was echoing them out to test the template pipeline and have tried all possible approaches
Echoing out all these different strings never displays backslashes and it doesn't seem to me to be a log display issue (accessing the raw log I never see a single backslash however I pass the paths).
This is my simple pipeline template to test what I'm doing
parameters:
- name: string1
type: string
default: C:\APPS\XYZ\
- name: string2
type: string
default: 'C:\APPS\XYZ\'
- name: string3
type: string
default: "C:\\APPS\\XYZ\\"
jobs:
- job: JOB
displayName: JOB
steps:
- checkout: none
- script: |
echo 1 ${{ parameters.string1 }}
echo 2 ${{ parameters.string2 }}
echo 3 ${{ parameters.string3 }}
Upvotes: 2
Views: 7995
Reputation: 3687
In the end the disappearance of the backslashes was only in echoing out values. I don't fully understand why this is happening but clearly the backslash is a special character and gets interpreted. By putting the strings to be printed inside single quotes this does not occur and the parameter values get printed out correctly.
This is the correct code
parameters:
- name: string1
type: string
# no quotes
default: C:\APPS\XYZ\
- name: string2
type: string
# single quotes
default: 'C:\APPS\XYZ\'
- name: string3
type: string
# double quotes
default: "C:\\APPS\\XYZ\\"
steps:
- checkout: none
- script: |
echo '1 ${{ parameters.string1 }}'
echo '2 ${{ parameters.string2 }}'
echo '3 ${{ parameters.string3 }}'
Upvotes: 1
Reputation: 3
First of all, you have a mistake in the second value - the single quote at the start is missing.
Second, you don't need quotes in paramaters value. If you set double quotes the rules for text are changed.
http://blogs.perl.org/users/tinita/2018/03/strings-in-yaml---to-quote-or-not-to-quote.html
Upvotes: 0