【问题标题】:Getting current build number in jenkins using python使用python在jenkins中获取当前版本号
【发布时间】:2016-10-17 23:06:19
【问题描述】:

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

脚本.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 "

【问题讨论】:

  • 肮脏的答案是做last_build_number + 1。我会打印j.get_job_info('sample123') 看看它是否有“currentBuild”或类似的东西。

标签: python jenkins jobs jenkins-api


【解决方案1】:

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

下面的代码 sn-p 来自他们的文档:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-03-17
    • 2021-10-24
    • 1970-01-01
    • 2011-11-02
    • 2013-09-06
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多