1.安装jenkins依赖包:
你可能会查询到有多种jenkins包,是的 没错。这里我就只介绍我用到的其中的一个jenkinsapi包,安装方式:
pip3 install jenkinsapi
然后查看是否安装成功,使用命令:
pip3 list
能查询到有jenkinsapi包就表示 安装成功了。
安装好依赖包以后,就可以连接jenkins 调用api:
from jenkinsapi.jenkins import Jenkins def Url_Get_Job_List(url, username, password): jenkins =Jenkins(url, username=username, password=password) count = 0 #遍历每个jenkins job for job_name in jenkins.keys(): #获取jenkins job的名字 my_job = jenkins.get_job(job_name) count = count + 1 #print “Job” + str(count) + " : "+job_name print (job_name) #Delete job删除 jenkins.delete_job(job_name) print("delete "+job_name +" successfully") if __name__=='__main__': Url_Get_Job_List("http://172.0.0.1:8080","admin","admin")
标签:__,jenkinsapi,name,python,count,job,jenkins,连接 From: https://www.cnblogs.com/pingguomang/p/17596909.html