summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Roxell <anders.roxell@linaro.org>2015-09-17 10:14:16 +0200
committerAnders Roxell <anders.roxell@linaro.org>2015-09-23 19:47:44 +0200
commit5af3048fec69d93e1230a117210fb518f8c58291 (patch)
treef94e5be0670578af5c28c343040f2b3bb689f9a7
parent41f55ed2dd0841d430811415bcdb9de932ffddb3 (diff)
add get_jenkins_variable.py
Utility to get jenkins variable via jenkins API (json file) Change-Id: I9fdbbb2edebfa61e31570b6944d16e2f342904bd Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
-rwxr-xr-xget_jenkins_variable.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/get_jenkins_variable.py b/get_jenkins_variable.py
new file mode 100755
index 0000000..ace8acf
--- /dev/null
+++ b/get_jenkins_variable.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+import os
+import json
+import urllib2
+import argparse
+
+ci_base_url = os.environ.get('CI_BASE_URL',
+ 'https://ci.linaro.org/jenkins/job/')
+
+def main(args):
+ input_arguments = dict()
+ input_arguments['json_url'] = args.json_url
+
+ request = urllib2.Request(ci_base_url + input_arguments['json_url'] +
+ '/lastSuccessfulBuild/api/json')
+ try:
+ response = urllib2.urlopen(request)
+ except urllib2.URLError, e:
+ if hasattr(e, 'reason'):
+ print 'Failed to reach %s.' % ci_base_url
+ print 'Reason: ', e.reason
+ print e.headers
+ elif hasattr(e, 'code'):
+ print 'Could not fulfill the request: %s' % ci_base_url
+ print 'Error code: ', e.code
+ print e.headers
+ sys.exit('Failed to get response.')
+ values = json.load(response)
+
+ if args.input_variable:
+ input_arguments['input_variable'] = args.input_variable
+ for item in values['actions'][0]['parameters']:
+ if input_arguments['input_variable'] in item.get('name'):
+ print item.get('value')
+ else:
+ config = json.dumps(values, indent=2)
+ print config
+
+if __name__ == '__main__':
+ parser = argparse.ArgumentParser()
+ parser.add_argument("json_url", help="url to json file")
+ parser.add_argument("--input_variable", help="variable to get back")
+ args = parser.parse_args()
+ main(args)
+# vim: set ts=8 sw=4 sts=4 et tw=80 fileencoding=utf-8 :