from common.utils import unicode_to_str
# remote jenkins build job
import requests
+import ast
class LocalError(Exception):
except Exception as e:
raise Exception(e)
-def get_pending_builds_with_parameter_for_job(job):
+def get_pending_builds_with_parameter():
- assert job
- build_queue_data = {}
cred = {'url': os.getenv('JENKINS_URL_INTERNAL'), \
'username': os.getenv('JENKINS_USER'), \
'password': os.getenv('JENKINS_PW')}
- jenkinsinst = get_jenkins_instance(job, cred)
- jq = jenkinsinst.get_queue()
- for pending_build in jq.get_queue_items_for_job(job):
- build_queue_data[pending_build.queue_id] = []
- for action in pending_build._data.get('actions', []):
- if type(action) is dict and 'parameters' in action:
- for param in action['parameters']:
- build_queue_data[pending_build.queue_id].append(param)
-
- return build_queue_data
+
+ path = '%s/queue/api/python' % (cred['url'])
+ path = '%s?tree=items[id,task[name],actions[parameters[name,value]]]' % path
+ resp = requests.post(path, auth=requests.auth.HTTPBasicAuth(cred['username'], cred['password']))
+ ret_obj = ast.literal_eval(resp.text)
+ return ret_obj.get("items")
import xml.etree.ElementTree as ElementTree
from common.repomaker import find_files, RepoMaker, RepoMakerError
-from common.buildtrigger import trigger_info, trigger_next, get_pending_builds_with_parameter_for_job
+from common.buildtrigger import trigger_info, trigger_next, get_pending_builds_with_parameter
from common.buildservice import BuildService
from common.backenddb import BackendDB
from common.prerelease import get_info_from_prerelease_name
return unresolvable_broken_packages
+def pending_build_exists(project_name):
+
+ try:
+ pending_build_queue = get_pending_builds_with_parameter()
+ if not pending_build_queue:
+ return False
+ for _queue in pending_build_queue:
+ if 'task' not in _queue or 'name' not in _queue.get('task') \
+ or os.getenv('JOB_NAME') != _queue.get('task').get('name'):
+ continue
+ for action in _queue.get('actions'):
+ if not 'parameters' in action:
+ continue
+ for param in action.get('parameters'):
+ name = param.get('name')
+ value = param.get('value')
+ if name == 'TRIGGER_INFO' and value:
+ pending_info = trigger_info(value, show=False)
+ if pending_info.get('project') == project_name \
+ and pending_info.get('event_type') == 'OBS_REPO_PUBLISHED':
+ print 'Found the same %s pending build is in the queue(%s)' \
+ % (pending_info.get('project'), _queue)
+ return True
+ except Exception as err:
+ print repr(err)
+ print 'Fail to check queue. Going forward accepted.'
+
+ return False
+
def main(action):
"""Script entry point.
Parameters:
content = trigger_info(os.getenv("TRIGGER_INFO"))
- try:
- # Skip this if the same build is in the queue
- pending_build_queue = get_pending_builds_with_parameter_for_job(os.getenv('JOB_NAME'))
- for _queue in pending_build_queue:
- for param in pending_build_queue[_queue]:
- name = param['name']
- if name == 'TRIGGER_INFO' and 'value' in param:
- pending_info = trigger_info(param['value'], show=False)
- if pending_info.get('project') == content.get('project') \
- and pending_info.get('event_type') == 'OBS_REPO_PUBLISHED':
- print 'SKIP THIS BUILD due to the same build %s is in the queue(%s)' \
- % (pending_info.get('project'), _queue)
- return -1
- except Exception as err:
- print repr(err)
- print 'Fail to check queue. Going forward accepted.'
+ # Skip this if the same build is in the queue
+ if pending_build_exists(content.get('project')) == True:
+ print 'SKIP THIS BUILD due to the same build is in the queue'
+ return 0
print '---[JOB STARTED: %s ]-------------------------' % action
global buildmonitor_enabled