import jenkins #importing jenkins python module
# Replace these values with your Jenkins server information
jenkins_url = 'http://your-jenkins-server-url'
username = 'your-username'
password = 'your-password'
# Connecting to Jenkins server
server = jenkins.Jenkins(jenkins_url, username=username, password=password)
# Specify Jenkins job name and build number
job_name = 'your-job-name'
build_number = 'your-build-number' # This can be 'lastBuild' for the latest build
# Get console output (log)
console_output = server.get_build_console_output(job_name, build_number)
# Get build information
build_info = server.get_build_info(job_name, build_number)
# Check for build result (success or failure)
if build_info['result'] == 'FAILURE':
# Retrieve errors from the console output
errors = [line for line in console_output.split('\n') if line.startswith('[ERROR]')] # you can modify the keyword based on your requirement
# Print errors
print("\nErrors:")
for error in errors:
print(error) #you can print the errors or you can send the output to an excel or text document to prepare reports
else:
print("\nBuild was successful.")
1条答案
按热度按时间x4shl7ld1#
您可以使用Python模块'python-jenkins'编写Python脚本来实现您想要的任务。这里是Jenkins python Package 器(https://pypi.org/project/python-jenkins/)的完整文档
字符串