Python版本- 3.10.4和Jenkins版本- 2.321我正在尝试使用Python脚本和Jenkins API获取构建信息。
from jenkinsapi.jenkins import Jenkins
def get_server_instance():
jenkins_url = 'My build URL/api/json?pretty=true'
server = Jenkins(jenkins_url, username = 'my user id', password = 'My API token')
return server
if __name__ == '__main__':
print (get_server_instance().version)
"""Get job details of each job that is running on the Jenkins instance"""
def get_job_details():
# Refer Example #1 for definition of function 'get_server_instance'
server = get_server_instance()
for j in server.get_jobs():
job_instance = server.get_job(j[0])
print ('Job Name:%s' %(job_instance.name))
print ('Job Description:%s' %(job_instance.get_description()))
print ('Is Job running:%s' %(job_instance.is_running()))
print ('Is Job enabled:%s' %(job_instance.is_enabled()))
脚本只返回Jenkins版本,而不是构建信息本身,它甚至没有给出任何错误来进一步工作,我在这里感到困惑,如何获得构建信息及其工件信息。
Output:- 2.321
任何协助或帮助将不胜感激。
1条答案
按热度按时间44u64gxh1#
您没有在main中调用get_job_details。