def jenkins_rebuild_obsolete(limit=5): current_jobs = set( [ i["name"] for i in jenkins.get_jobs() if (re.match(config.branch_name_regexp, i["name"]) and i["color"] == "blue") ] ) obsolete_jobs = set( [ i[0] for i in dbcon.execute( """select branch from branch where jira_task_status='Need testing' and git_merge_status='MERGED' and (git_master_head_remote is git_master_head_local_done) and (git_remote_head_remote is git_remote_head_local_done) and not (git_branch_head_merged is jenkins_branch_head_merged) order by jira_task_priority;""" ).fetchall() ] ) jobs_to_rebild = list(obsolete_jobs.intersection(current_jobs))[:limit] if TRACE: print "Current_jobs", current_jobs print "Obsolete_jobs", obsolete_jobs print "[JENKINS]: Rebuild obsolete jobs: " + repr(jobs_to_rebild) jenkins.trigger_build_jobs(jobs_to_rebild)
def jenkins_add_jobs(limit=5): current_jobs = set([i["name"] for i in jenkins.get_jobs()]) branches_to_build = set( [ i[0] for i in dbcon.execute( """select branch from branch where (git_master_head_remote is git_master_head_local_done) and (git_remote_head_remote is git_remote_head_local_done) and jira_task_status='Need testing' and git_merge_status='MERGED' and (jenkins_branch_head_merged is null);""" ).fetchall() ] ) new_jobs = list(branches_to_build.difference(current_jobs))[:limit] if TRACE: print "Current jobs", current_jobs print "Ready to build jobs", branches_to_build print "[JENKINS] add jobs:" + repr(new_jobs) if new_jobs: config_template = jenkins.get_config() jobs_and_configs = map( lambda job: ( job, config_template.replace("remotes/origin/master", job).replace( config.GIT_REMOTE_PATH, "file://" + config.GIT_WORK_DIR + "/.git/" ), ), new_jobs, ) jenkins.create_jobs(jobs_and_configs) jenkins.trigger_build_jobs(new_jobs)
def jenkins_rebuild_failed_all(): failed_jobs = [ i["name"] for i in jenkins.get_jobs() if (re.match(config.branch_name_regexp, i["name"]) and i["color"] != "blue") ] if TRACE: print "[JENKINS]: Rebuild failed jobs: " + repr(failed_jobs) jenkins.trigger_build_jobs(failed_jobs)
def jenkins_rebuild_failed_random(): import random failed_jobs = [ i["name"] for i in jenkins.get_jobs() if (re.match(config.branch_name_regexp, i["name"]) and i["color"] != "blue") ] if len(failed_jobs) > 0: random_job = failed_jobs[random.randint(0, len(failed_jobs) - 1)] if TRACE: print "[JENKINS]: Rebuild random failed job: " + repr(random_job) jenkins.trigger_build_job(random_job)
def jenkins_delete_jobs(limit=5): jobs = set([i["name"] for i in jenkins.get_jobs() if re.match(config.branch_name_regexp, i["name"])]) branches = set( [ i[0] for i in dbcon.execute( """select branch from branch where jira_task_status='Need testing' or jira_task_status is null;""" ).fetchall() ] ) for branch in list(jobs.difference(branches))[:limit]: if TRACE: print "[JENKINS] delete job:" + repr(branch) jenkins.delete_job(branch)