python jenkins 打包构建代码的示例代码

python jenkins 打包构建代码

# pip install python-jenkins

import jenkins

import pprint

import time

# 在jenkins 的Configure Global Security下 , 取消“防止跨站点请求伪造(Prevent Cross Site Request Forgery exploits)”的勾选

server = jenkins.Jenkins('http://192.168.100.151:8081', username='admin', password='admin')

# 下次构建的id

jenkins_next_build_number = server.get_job_info("test")['nextBuildNumber']

# 开始构建 build_job(self, name, parameters=None, token=None) parameters可以加入参数

server.build_job("test", parameters={'version': '1.0.2', "env": "test"})

time.sleep(10)

while True:

time.sleep(1)

if server.get_job_info("test")['lastCompletedBuild']['number'] == jenkins_next_build_number:

print("-------------------构建完成-----------------------")

break

result = server.get_build_console_output("test", jenkins_next_build_number)

print(result)

info = server.get_build_info("test", jenkins_next_build_number)

print(f"构建时间 {int(info['duration']) / 1000}秒")

if server.get_job_info("test")['lastCompletedBuild']['number'] == \

server.get_job_info("test")['lastSuccessfulBuild']['number']:

print("构建成功")

else:

print("构建失败")

以上是 python jenkins 打包构建代码的示例代码 的全部内容, 来源链接: utcz.com/z/323482.html

回到顶部