Created
March 24, 2015 22:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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