通过TeamCity将带有引号的参数传递给PowerShell脚本 [英] Pass argument with quotes to PowerShell script via TeamCity
问题描述
我们正在通过TeamCity调用PowerShell脚本。我们要传递包含引号的参数,例如:
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%"
其中 system.MyParam
设置为< xml>< elem attr = value>< / elem>< / xml>
。不幸的是,这失败了:
Where system.MyParam
is set to <xml><elem attr="value"></elem></xml>
. Unfortunately, this fails with:
无法处理参数
MyParam
的参数转换。无法将值< xml>< elem
转换为类型System.Xml.XmlDocument
。错误:解析名称时发生了意外的文件结尾。第1行,...
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:
- 简单地传递参数
- 使用双引号(例如attr = value)
- 使用PowerShell的反引号转义机制(例如attr =` value`)
- 在整个参数周围使用单引号(仅在value不包含空格的情况下有效)
- 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)
推荐答案
由于您的问题是输入XML字符串包含双引号属性值,因此可能的解决方法使用的是单引号属性值。
As your problem is that the input XML string contains double-quoted attribute values, a possible workaround could be using single-quoted attribute values.
这篇关于通过TeamCity将带有引号的参数传递给PowerShell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!