问题
We're calling a PowerShell script via TeamCity. We want to pass a parameter which contains quotes, e.g.:
Build step : PowerShell
Script file : foo/bar/my.ps1
Script arguments : -MyParam "%system.MyParam%"
Where system.MyParam
is set to <xml><elem attr="value"></elem></xml>
. Unfortunately, this fails with:
Cannot process argument transformation on parameter
MyParam
. Cannot convert value "<xml><elem
" to type "System.Xml.XmlDocument
". Error: "Unexpected end of file while parsing Name has occurred. Line 1, ..."
Anybody knows how to correctly pass double quotes?
What I've tried so far and didn't work:
- Simply passing the parameter
- Using double double quotes (i.e. attr=""value"")
- Using PowerShell's backtick escape mechanism (i.e. attr=`"value`")
- Using single quotes around the whole parameter (works only if value does not contain spaces)
回答1:
As your problem is that the input XML string contains double-quoted attribute values, a possible workaround could be using single-quoted attribute values.
回答2:
Backtick (`
) is the PSH escape character. So you can use "`""
to pass a string containing a double quote character.
You can also use single quotes around PSH strings – and also avoid expression interpolation: '"'
is also a string with a single double quotes.
But remember you need to ensure the quoting works for both the launcher (sending the arguments) and for the script itself: you may need to escape the escapes as well.
来源:https://stackoverflow.com/questions/32246144/pass-argument-with-quotes-to-powershell-script-via-teamcity