0

TeamCity allows build parameters to be defined, and then used in build scripts.

Eg define a parameter output_dir which is set to doc\release_notes. TeamCity documentation says to use it in build scripts with % escapes, eg %output_dir%.

But, how can such parameters be safely used in Python build scripts without being messed up by various characters?

Eg if the Python build script has

output_dir = "%output_dir%"

Then various characters in the build parameter can cause problems.

  1. \ will be treated as an escape character, so doc\release_notes becomes two lines, doc and elease_notes separated by a CR character \r.
  2. A trailing \ will "escape" the closing quote, so for release_notes\ the Python interpreter will generate a syntax error, saying the string "release_notes\" is unterminated.
  3. A double-quote character will prematurely terminate the string, so 9" nails will be seen by Python as the string "9" followed by a syntax error.

Using a Python "raw string literal", eg

output_dir = r"%output_dir%"

solves (1) but not (2) or (3).

Using a Python "raw string multi-line literal", eg

output_dir = r"""%output_dir%"""

solves (1), but not (2), and solves (3) except if the " character is at the end of the string.

How can TeamCity build parameters be safely used in Python build scripts without being messed up by various string escape character issues?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.