qdyxmas's Room

Done is better than perfect...

python调用 jenkins动态build服务

import jenkins
import time
import sys
class Build_Baseline():
    def __init__(self,branch = "dev"):    
        self.jenkins_server_url="https://xxxx.xxxx.xxxx"
        self.user_id="xxxxxxxxxxxx"
        self.api_token="xxxxxxxxxxxxxxxxx"
        self.branch = branch
        self.server=jenkins.Jenkins(self.jenkins_server_url, username=self.user_id, password=self.api_token)
        self.job_name = "Baseline_Build_Service"
    def build_base_service(self):
        base_dict = {"environment": self.branch,
        "services":"ai_worker,cad_processor,ppt_service,new_task_center,solar_algorithm,data_service,algorithm,backend,websocket,facade_algorithm", 
        "ai_worker_servers": "xkooltest.3322.org", 
        "cad_processor_servers": "xkooltest.3322.org", 
        "ppt_service_servers": "xkooltest.3322.org",
        "new_task_center_servers": "xkooltest.3322.org", 
        "solar_algorithm_servers": "xkooltest.3322.org",
        "data_service_servers": "xkooltest.3322.org", 
        "algorithm_servers": "xkooltest.3322.org",
        "backend_servers": "xkooltest.3322.org",
        "websocket_servers": "xkooltest.3322.org",
        "facade_algorithm_servers": "xkooltest.3322.org", 
        "baseline_servers": ""}
        self.server.build_job(name = self.job_name,parameters=base_dict,token="xkool_baseline")

    def build_baseline(self):
        base_dict = {"services":"baseline", "ai_worker_servers": "", "cad_processor_servers": "", "ppt_service_servers": "", "new_task_center_servers": "", "solar_algorithm_servers": "", "data_service_servers": "", "algorithm_servers": "", "backend_servers": "", "websocket_servers": "", "facade_algorithm_servers": "", "baseline_servers": "xkooltest.3322.org","environment": self.branch}
        self.server.build_job(name = self.job_name,parameters=base_dict,token="xkool_baseline")
if __name__ == "__main__":
    if len(sys.argv) == 2:
        branch = sys.argv[1]
    else:
        branch = "dev"
    bb = Build_Baseline(branch)
    bb.build_base_service()
    bb.build_baseline()

标签 

评论