except Exception as e:
raise Exception(e)
+def get_pending_builds_with_parameter_for_job(job):
+
+ 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
+
import xml.etree.ElementTree as ElementTree
from common.repomaker import find_files, RepoMaker, RepoMakerError
-from common.buildtrigger import trigger_info, trigger_next
+from common.buildtrigger import trigger_info, trigger_next, get_pending_builds_with_parameter_for_job
from common.buildservice import BuildService
from common.backenddb import BackendDB
from common.prerelease import get_info_from_prerelease_name
action - cleanup or create_images
"""
+ 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.'
+
print '---[JOB STARTED: %s ]-------------------------' % action
global buildmonitor_enabled
buildmonitor_enabled = os.getenv("BUILDMONITOR_ENABLED", "0") != "0"
base_path = os.getenv('PATH_REPO_BASE')
live_repo_base = os.getenv('PATH_LIVE_REPO_BASE')
- content = trigger_info(os.getenv("TRIGGER_INFO"))
-
project = content.get("project") or content.get("sourceproject")
build = BuildService(obs_api, obs_user, obs_passwd)