QA亮子的记事本

记录开发测试中碰到的问题和解决办法

导航

Python-Jenkins 查询job是否存在

def check_jobs_from_jenkins(job_names):
    if isinstance(job_names, str):
        job_names = [job_names]
    job_dict = {}
    for job_name in job_names:
        job_dict[job_name] = True if is_job_exists(job_name) else False
    return job_dict


def get_jenkins():
    return jenkins.Jenkins(get_ci_url(), get_ci_user(), get_ci_password())


def is_job_exists(job_name):
    j = get_jenkins()
    try:
        j.assert_job_exists(job_name)
        logging.info('----- is_job_exists::%s::True-----' % job_name)
        return True
    except jenkins.JenkinsException:
        logging.info('----- is_job_exists::%s::False-----' % job_name)
        return False
    finally:
        pass

 

posted on 2015-09-25 11:02  sdet_liang  阅读(1033)  评论(0编辑  收藏  举报