4

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)
D.R.
  • 20,268
  • 21
  • 102
  • 205

2 Answers2

2

As your problem is that the input XML string contains double-quoted attribute values, a possible workaround could be using single-quoted attribute values.

ulrichb
  • 19,610
  • 8
  • 73
  • 87
1

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.

Richard
  • 106,783
  • 21
  • 203
  • 265
  • Backtick didn't work. Single quotes seem to work, however, fail if value contains a space character. Any other ideas? – D.R. Aug 27 '15 at 10:03
  • 1
    @D.R. I think I would look to see if I one could get Team City to just echo back what has been sent. When one program is creating arguments that are passed to another (especially with different quoting and argument parsing rules) is easiest when you can see each step. – Richard Aug 27 '15 at 10:29
  • Upvoted for good answer, however, I don't have the time atm to investigate and used the proposed alternative by @ulrichb. – D.R. Aug 27 '15 at 15:42