圆月山庄资源网 Design By www.vgjia.com

官方文档:

需求:当1个job启动构建后,获取它的构建状态.(成功,失败,驳回,构建中,正在排队)

关键函数:

获取job是否在排队的结果

获取正在排队构建的job队列 即pending状态中的所有job,如果没有 pending状态的job即返回1个空列表

queue_info = server.get_queue_info()

获取job构建结果

server.get_build_info(name, build_number)[
      'result'] # 构建结束 SUCCESS|FAILURE<class 'str'>  ABORTED <class 'str'> 构建中None None <class 'NoneType'>

代码示例:

def get_build_state(server, name, build_number):
  '''

  :param name: job_name
  :param build_number: 最后1次构建序号
  :param:jenkins_server
  :return: 最后1次构建状态 pending,success,false,building
  '''
  build_state = None

  # 获取正在排队构建的job队列 即pending状态中的所有job,如果没有 pending状态的job即返回1个空列表
  queue_info = server.get_queue_info()

  if queue_info:
    for queue_job_info in queue_info:
      if queue_job_info['task']['name'] == name:
        # msg = 'pending期,排队构建中'
        build_state = 'pending'
  else:

    build_state = server.get_build_info(name, build_number)[
      'result'] # 构建结束 SUCCESS|FAILURE<class 'str'>  ABORTED <class 'str'> 构建中None None <class 'NoneType'>
  return build_state

通过接口将该功能封装起来

@build_bp.route('/gotest/api/getBuildState', methods=['POST'])
def get_job_build_state():
  '''
    获取job构建状态
    return:build_state Success,Faild,Pending,Building
    '''
  data = request.get_json()
  job_name = data['job_name']

  server = get_jenkins_server()
  # 获取job的最后次构建号
  lastbuildNumber = server.get_job_info(job_name)['lastBuild']['number']
  #获取构建状态
  build_state = get_build_state(server, job_name, lastbuildNumber)

  if build_state is None:
    build_msg = 'Building'
  elif build_state == 'SUCCESS':
    build_msg = 'SUCCESS'
  elif build_state == 'FAILURE':
    build_msg = 'FAILURE'
  elif build_state == 'ABORTED':
    build_msg = 'ABORTED'
  elif build_state =='pending':
    build_msg = 'pending'

  response = {}
  datas={}
  response['code'] = 200
  response['msg'] = 'OK'

  datas['build_state'] = build_msg
  datas['buildNumber'] = lastbuildNumber
  response['datas'] = datas

  return response

测试接口:

import requests
url='http://127.0.0.1:5000/gotest/api/getBuildState'
data={'job_name':'android_official'}

r = requests.post(url,json=data)
print(r.text)

响应:

{"code":200,"datas":{"buildNumber":1010,"build_state":"SUCCESS"},"msg":"OK"}

以上这篇Python-jenkins 获取job构建信息方式就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

标签:
Python,jenkins,job

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。