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)