使用python在jenkins中获取当前的内部版本号

时间:2016-10-17 23:06:20

标签: python jenkins jobs jenkins-api

我有一个python脚本,我试图在jenkins中获取当前的作业编号。下面的脚本给出了最后的构建号以及构建是成功还是失败。如何获取当前的内部版本号?我的意思是当我运行这个脚本时,它将使用新的内部版本号进行构建,如何获得当前的内部版本号?

script.py

import jenkins
import urllib2 
import urllib
import sys

j = jenkins.Jenkins('http://localhost:8080')
if not j.job_exists('sample1234'):
    j.create_job('sample1234', jenkins.EMPTY_CONFIG_XML)

j.reconfig_job('sample1234', jenkins.RECONFIG_XML)
j.build_job('sample1234')

last_build_number = j.get_job_info('sample123')['lastCompletedBuild'] ['number']
print last_build_number

build_info=j.get_build_info('sample123',last_build_number)
if build_info['result']=='SUCCESS':
    print "Build Success "
else:
    print " Build Failed "

1 个答案:

答案 0 :(得分:0)

我认为你正在寻找的答案是在python-jenkins documentation中,特别是在例9中

以下代码段来自他们的文档:

next_bn = server.get_job_info('job_name')['nextBuildNumber']
server.set_next_build_number('job_name', next_bn + 50)

我认为你真的只需要当前/下一个内部版本号的第一行。需要注意的是,你的jenkins需要plugin