from xml.sax.saxutils import escape
from time import sleep
import datetime
+import requests
from osc import core
from gitbuildsys.errors import ObsError
# First store current build and all the rest queued builds
build_queue = []
job = os.getenv('JOB_NAME')
- cred = {'url': os.getenv('REMOTE_JENKINS_URL'), \
- 'username': os.getenv('REMOTE_JENKINS_USER'), \
- 'password': os.getenv('REMOTE_JENKINS_PW')}
+ cred = {'url': os.getenv('JENKINS_URL_INTERNAL'), \
+ 'username': os.getenv('JENKINS_USER'), \
+ 'password': os.getenv('JENKINS_PW')}
jenkinsinst = get_jenkins_instance(job, cred)
- curr_build = jenkinsinst.get_job(job).get_build(int(os.getenv('BUILD_NUMBER')))
- up_id = curr_build.get_upstream_build_number()
- if up_id is None: up_id = 0
+ try:
+ curr_build = jenkinsinst.get_job(job).get_build(int(os.getenv('BUILD_NUMBER')))
+ except Exception as err:
+ print str(err)
+ curr_build = None
+
curr_data = {}
- for k in curr_build.get_actions()['parameters']:
- curr_data[k['name']] = k['value']
- build_queue.append({'%d-%d' % (up_id, curr_build._data['queueId']): curr_data})
+ up_id = 0
+ if curr_build:
+ up_id = curr_build.get_upstream_build_number()
+ if up_id is None:
+ up_id = 0
+ for k in curr_build.get_actions()['parameters']:
+ curr_data[k['name']] = k['value']
+ build_queue.append({'%d-%d' % (up_id, curr_build._data['queueId']): curr_data})
+ else:
+ #FIXME: python-jenkinsapi fail to retrive internal url. Use api/python call instead.
+ path = '%s/job/%s/%s/api/python' % (cred['url'], os.getenv('JOB_NAME'), os.getenv('BUILD_NUMBER'))
+ path = path.replace('://', '://%s:%s@' % (cred['username'], cred['password']))
+ resp = requests.get(path)
+ ret_obj = ast.literal_eval(resp.text)
+ for a in ret_obj['actions']:
+ if 'causes' in a:
+ if up_id == 0 and 'upstreamBuild' in a['causes'][0]:
+ up_id = int(a['causes'][0]['upstreamBuild'])
+ if 'parameters' in a:
+ for p in a['parameters']:
+ curr_data[p['name']] = p['value']
+ build_queue.append({'%d-%d' % (up_id, int(ret_obj['queueId'])): curr_data})
+
#TODO: Keep original process
if up_id != 0:
jq = jenkinsinst.get_queue()
trigger_next("BUILD-MONITOR_%d" % sr_count, bm_data)
if __name__ == '__main__':
- try:
+ #try:
sys.exit(entry(sys.argv))
- except Exception as err:
- print err
- sys.exit(1)
+ #except Exception as err:
+ # print err
+ # sys.exit(1)