Created
December 31, 2012 13:24
-
-
Save anonymous/4419742 to your computer and use it in GitHub Desktop.
读取jenkins api(json),替换andoird编译是的自定义rules内的版本号
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 json,sys,os | |
import urllib2 | |
url = 'http://x.x.x.x/job/x.x.x.x/lastBuild/api/json' | |
try: | |
u = urllib2.urlopen(url).read() | |
except: | |
exit(100) | |
baseim = json.loads(u) | |
baseim_revision = baseim["changeSet"]['revisions'][0]['revision'] | |
print baseim_revision | |
revision_with_baseim = ">%s-BASEIM-%s<" % (os.environ['SVN_REVISION'],baseim_revision) | |
new_rules = [] | |
with open("custom_rules.xml") as f: | |
for line in f: | |
new_rules.append(line.replace('>${env.SVN_REVISION}<',revision_with_baseim)) | |
print "".join(new_rules) | |
with open("custom_rules.xml","w") as f: | |
f.write("".join(new_rules)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment