使用Python在Jenkins中获取当前构建号

2024-09-25 16:32:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个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 "

Tags: importbuildinfo脚本numbergetif版本号
1条回答
网友
1楼 · 发布于 2024-09-25 16:32:51

我认为您要寻找的答案是在pythonjenkinsdocumentation中,具体地说是在示例9中

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

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

我想你只需要当前/下一个版本号的第一行。警告是你需要这个给你的詹金斯。在

相关问题 更多 >