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

yipeiwu_com6年前Python基础

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设计】。

相关文章

Pytorch实现的手写数字mnist识别功能完整示例

本文实例讲述了Pytorch实现的手写数字mnist识别功能。分享给大家供大家参考,具体如下: import torch import torchvision as tv impor...

Python时间差中seconds和total_seconds的区别详解

如下所示: import datetime t1 = datetime.datetime.strptime("2017-9-06 10:30:00", "%Y-%m-%d %H:...

Python基于tkinter模块实现的改名小工具示例

本文实例讲述了Python基于tkinter模块实现的改名小工具。分享给大家供大家参考,具体如下: #!/usr/bin/env python #coding=utf-8 # #...

Python3删除排序数组中重复项的方法分析

本文实例讲述了Python3删除排序数组中重复项的方法。分享给大家供大家参考,具体如下: 给定一个排序数组,你需要在[原地]删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新...

python文件绝对路径写法介绍(windows)

python在描述路径时有两种方式: 'd:\\a.txt',转义的方式 r'd:\a.txt',声明字符串不需要转义 (使用raw string,也就是在string'前面加r,告诉p...