def addtask(username, jenkinsurl, jobname, specifynode, build_params):
    mysql = mysqlLib()
    try:
        param = (username ,jenkinsurl, jobname, json.dumps(build_params), 0)
        n,last_id = mysql.add_task(param)
        print(u"INFO, job initial, 0")
        unique_id = last_id
        if (specifynode == 1):
            J = Jenkins(jenkinsurl)
            jobs = Jobs(J)
            job = jobs[jobname]
            build_params['UNIQUE_ID'] = unique_id
            invoke = job.invoke(build_params=build_params)
            print("INFO, specifynode true")
        elif (specifynode == 0):
            client = gear.Client()
            client.addServer(gear_server, port = gear_port)
            client.waitForServer()  # Wait for at least one server to be connected
            build_params['UNIQUE_ID'] = unique_id
            job = gear.Job('build:' + jobname, json.dumps(build_params))
            client.submitJob(job)
            print("INFO, specifynode false")
        param=(1, unique_id)
        mysql.update_task_status(param)
        print(u"INFO, job submit, 1")
        print(u"INFO, job unique id :" + str(unique_id))
        url = "http://10.48.55.39:8889/pb/jenkins/status/?job=" + str(unique_id)
        print(u"INFO, you could link " + url + " to trace the job status")
    except Exception as e:
        print(e)
    finally:
        mysql.close()
示例#2
0
def gearmanjobstop(unique_id):
    datalist_info = {}
    output = None
    try:
        client = gear.Client()
        client.addServer(gear_server, port=gear_port)
        client.waitForServer()  # Wait for at least one server to be connected
        param = {"id": unique_id}
        mysql = mysqlLib()
        datalist = mysql.query_task(param)
        mysql.close()
        jobname = datalist[0][3]
        status = datalist[0][5]
        build_number = datalist[0][6]

        if (int(status) == 2):
            build_params = {"name": jobname, "number": str(build_number)}
            job = gear.Job("stop:" + gear_server, json.dumps(build_params))
            client.submitJob(job)
            print("INFO, job aborte start")
            output = "INFO, job aborte start"
        else:
            print("INFO, job not running now")
            output = "INFO, job not running now"
    except Exception as e:
        print(e)
        output = "ERROR, " + str(e)
    finally:
        datalist_info['output'] = output
        return datalist_info
示例#3
0
def gearmanjobstop(unique_id):
    datalist_info = {}
    output = None
    try:
        client = gear.Client()
        client.addServer(gear_server, port = gear_port)
        client.waitForServer()  # Wait for at least one server to be connected
        param={"id":unique_id}
        mysql=mysqlLib()
        datalist=mysql.query_task(param)
        mysql.close()
        jobname = datalist[0][3]
        status = datalist[0][5]
        build_number = datalist[0][6]

        if (int(status) == 2):
            build_params = {"name":jobname, "number":str(build_number)}
            job = gear.Job("stop:" + gear_server, json.dumps(build_params))
            client.submitJob(job)
            print("INFO, job aborte start")
            output = "INFO, job aborte start"
        else:
            print("INFO, job not running now")
            output = "INFO, job not running now"
    except Exception as e:
        print(e)
        output = "ERROR, " + str(e)
    finally:
        datalist_info['output'] = output
        return datalist_info
示例#4
0
def addtask(username, jenkinsurl, jobname, specifynode, build_params):
    mysql = mysqlLib()
    url = None
    try:
        param = (username, jenkinsurl, jobname, json.dumps(build_params), 0)
        n, last_id = mysql.add_task(param)
        print(u"INFO, job initial, 0")
        unique_id = last_id
        if (specifynode == 1):
            J = Jenkins(jenkinsurl)
            jobs = Jobs(J)
            job = jobs[jobname]
            build_params['UNIQUE_ID'] = unique_id
            invoke = job.invoke(build_params=build_params)
            print("INFO, specifynode true")
        elif (specifynode == 0):
            client = gear.Client()
            client.addServer(gear_server, port=gear_port)
            client.waitForServer(
            )  # Wait for at least one server to be connected
            build_params['UNIQUE_ID'] = unique_id
            job = gear.Job('build:' + jobname, json.dumps(build_params))
            client.submitJob(job)
            print("INFO, specifynode false")
        param = (1, unique_id)
        mysql.update_task_status(param)
        print(u"INFO, job submit, 1")
        print(u"INFO, job unique id :" + str(unique_id))
        url = "http://10.48.55.39:8889/jobstatus/?job=" + str(unique_id)
        print(u"INFO, you could link " + url + " to trace the job status")
    except Exception as e:
        print(e)
    finally:
        mysql.close()
        return url
示例#5
0
def addtask(jenkinsurl, jobname, build_params):
    mysql = mysqlLib()
    try:
        #任务初始化,0
        param = (jenkinsurl, jobname, json.dumps(build_params), 0)
        n,last_id = mysql.add_task(param)
        print(u"#任务初始化,0")

        J = Jenkins(jenkinsurl)
        jobs = Jobs(J)
        job = jobs[jobname]
        invoke = job.invoke(build_params=build_params)

        '''is_queued = invoke.is_queued()
        while(is_queued is False):
            time.sleep(1)
            is_queued = invoke.is_queued()
        #任务排队中,1
        param=(1, last_id)
        mysql.update_task_status(param)
        print(u"#任务排队,1")

        is_running = invoke.is_running()
        while(is_running is False):
            time.sleep(1)
            is_running = invoke.is_running()
        #任务执行中,2
        param=(2, last_id)
        mysql.update_task_status(param)
        print(u"#任务执行,2")'''


        #更新任务 build_number
        build_number = invoke.get_build_number()
        param=(build_number, last_id)
        mysql.update_task_build_number(param)
        print build_number


        '''is_running = invoke.is_running()
        while(is_running is True):
            time.sleep(1)
            is_running = invoke.is_running()
        #任务执行完成,3
        param=(3, last_id)
        mysql.update_task_status(param)
        print(u"#任务完成,3")'''

    except Exception as e:
        logging.ERROR(e)
        #任务执行异常,4
        param=(4, last_id)
        mysql.update_task_status(param)
        print(u"#任务异常,4")
    finally:
        mysql.close()
示例#6
0
def addtask(jenkinsurl, jobname, build_params):
    mysql = mysqlLib()
    try:
        #任务初始化,0
        param = (jenkinsurl, jobname, json.dumps(build_params), 0)
        n, last_id = mysql.add_task(param)
        print(u"#任务初始化,0")

        J = Jenkins(jenkinsurl)
        jobs = Jobs(J)
        job = jobs[jobname]
        invoke = job.invoke(build_params=build_params)
        '''is_queued = invoke.is_queued()
        while(is_queued is False):
            time.sleep(1)
            is_queued = invoke.is_queued()
        #任务排队中,1
        param=(1, last_id)
        mysql.update_task_status(param)
        print(u"#任务排队,1")

        is_running = invoke.is_running()
        while(is_running is False):
            time.sleep(1)
            is_running = invoke.is_running()
        #任务执行中,2
        param=(2, last_id)
        mysql.update_task_status(param)
        print(u"#任务执行,2")'''

        #更新任务 build_number
        build_number = invoke.get_build_number()
        param = (build_number, last_id)
        mysql.update_task_build_number(param)
        print build_number
        '''is_running = invoke.is_running()
        while(is_running is True):
            time.sleep(1)
            is_running = invoke.is_running()
        #任务执行完成,3
        param=(3, last_id)
        mysql.update_task_status(param)
        print(u"#任务完成,3")'''

    except Exception as e:
        logging.ERROR(e)
        #任务执行异常,4
        param = (4, last_id)
        mysql.update_task_status(param)
        print(u"#任务异常,4")
    finally:
        mysql.close()