Using Python Jenkins API endpoints, you can automate your Jenkins servers. You shall install plugins, set the next build number and can do a lot more using Jenkins Python REST endpoints. In this blog article, you will learn step by step methods of installing and automating Jenkins server using Python code.
Python Jenkins API Package Installation
pip install python-jenkins
Connecting Jenkins Server
Connecting your Jenkins server is straight forward. Import ‘jenkins’ module and connect the server using URL, username, and password as shown below.
import jenkins try: server = jenkins.Jenkins('http://localhost:8080', username='admin', password='admin') except Exception as e: print(e)
Updating Build Number
next_bn = server.get_job_info('job_name')['nextBuildNumber'] server.set_next_build_number('job_name', next_bn + 50)
Get Test Results
Let’s say you wish to display a specific build’s test results, Using ‘get_build_test_report’ method, you can retrieve the test results for a Jenkins build. Not only that even If you intent to create an automation testing metrics utility, this method would be an ideal option to retrieve and display specific build’s test results.
Plugin Details
If you have a common test automation framework which is used widely in your organization, then you can get all the installed plugins details, identify the missing plugins which are recommended for your automation testing framework, and suggest them in Jenkins console window.
Enabling & Disabling Jobs
You shall enable & disable Jenkins jobs based on your automated script outcome. For instance: If a job is to be scheduled within a stipulated time frame with some valid condition and if the same needn’t be executed, then you use enabling & disabling Jenkins job options using Jenkins API endpoints.
Conclusion
As a QA company, we use Jenkins, TeamCity, and BuildBot for continuous integration of various automation testing projects. However, operating Jenkins server using Python offers greater flexibility to extract and control jobs via coding. On a parting noted we thank you very much for reading this blog article and hereby coclude with a hope that you have enjoyed this blog article. See you soon with more insightful articles !!!
Comments(0)