Skip to content

Instantly share code, notes, and snippets.

@sveinungkb
Created March 24, 2015 22:58
Show Gist options
  • Save sveinungkb/e713f3e1f0c8dd281d15 to your computer and use it in GitHub Desktop.
Save sveinungkb/e713f3e1f0c8dd281d15 to your computer and use it in GitHub Desktop.
This python script will look for a regexp pattern in whatever is piped to it, and echo back a Team City service message to set this as a build time variable using a service message.
import fileinput
import sys
import re
valuePair = sys.argv[1]
name = valuePair.split("=")[0]
valuePattern = valuePair.split("=")[1]
if not (name and valuePattern):
print("Call like this 'echo \"Lorem ipsum doler sit\" | python tc-grep-set-parameter.py 'jibberish=(ipsum)'")
exit(1)
print("Will look for pattern %s for value: %s"% (valuePattern, name))
regexp = re.compile(valuePattern)
input_lines = fileinput.input(sys.argv[2:])
for output_line in input_lines:
sys.stdout.write(output_line)
match = regexp.search(output_line)
if match:
print("##teamcity[setParameter name='%s' value='%s']"% (name, match.groups()[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment