Jenkins API
Arie Bregman
InfuseCon@2018
Agenda
● Jenkins API
○ Overview
○ How to use
○ Examples
○ The ugly side
● Pykins
○ Overview
○ Examples
Jenkins API overview● REST API
● Several data formats
○ XML
○ JSON
○ Python
● Retrieve Data
○ Jobs, Builds, Plugins, Nodes
● Actions
○ Trigger Jobs, Update Plugins
Python?
Why using Jenkis API?
● Dashboard
● Scripts
● Pull the specific data you need
● Jenkins UI is bad for your health
Using Jenkins API
● Add ‘/api’ to Jenkins URL
○ https://my_jenkins/api
○ General permanent description + relevant documentation to the endpoint of your
URL
● https://my_jenkins/job/my_job/api
● Add /api/json or /api/xml to get the actual data
○ Same data, different formats
○ There is a link at the the bottom of each page
in Jenkins UI
● Next, examples! :)
Example #1 - Baby Steps
https://<jenkins_server>/api/json
● Master server
● Jobs
● Views
{"_class":"hudson.model.Hudson","assignedLab
els":[{}],"mode":"NORMAL","nodeDescription":"t
he master Jenkins
node","nodeName":"","numExecutors":2,"descri
ption":null,"jobs":[{"_class":"org.jenkinsci.plu
gins.workflow.job.WorkflowJob","name":"ov
b-poc","url":"http://X/job/ovb-
poc/","color":"red"},{"_class":"org.jenkinsci.
plugins.workflow.job.WorkflowJob","name":
"bla-poc","url":"http://X/job/bla-
poc/","color":"blue"},...
Example #2 - Depth
https://<jenkins_server>/api/json?depth=1
● Depth = 1 -> Description, Builds, Health report
● Depth = 2 -> SCM changes, artificats
● ...
● Depth = 10
Example #3 - Tree
https://<jenkins_server>/api/json?tree=jobs[name]
● tree=key[field1, field2, field3, subkey[subfield1, subfield2]]
● Elements and sub-elements of a tree you want to get
● Nested as required
{"_class":"org.jenkinsci.plugins.workflow.job.WorkflowJob","name":"my_job"},{"_clas
s":"org.jenkinsci.plugins.workflow.job.WorkflowJob","name":"Z-
job"},{"_class":"org.jenkinsci.plugins.workflow.job.WorkflowJob","name":"Y-
job"},{"_class":"org.jenkinsci.plugins.workflow.job.WorkflowJob","name":"X-job"}, ...
Example #4 - Tree with subkeys
https://<my_j>/api/json?tree=jobs[name,lastBuild[result,changeSet[items[author]]]]
{"_class":"hudson.model.FreeStyleProject","name":"export-results-to-polarion-
poc""lastBuild":{"_class":"hudson.model.FreeStyleBuild",,"result":"FAILURE","chang
eSet":{"_class":"hudson.plugins.git.GitChangeSetList","items":[]}}}
The ugly side of Jenkins API
● http://my_jenkins/api/json?kowabunga will work just fine
● https://<jenkins_server>/api/json?depth=20 is the easiest way to kill a
Jenkins server
● Documentation
Python Libraries
● python-jenkins
○ OpenStack project
● Jenkinsapi
○ Maintained by pycontribs
○ More active at this point of time
Pykins
● Both Python API and CLI for Jenkins in one package!
● Custom calls support
● Additional functionality to Jenkins
● Maintained by couple of companies
Example #1 - get jobs
>>> j = pykins.Jenkins(“http://my_jenkins”)
>>> j.get_jobs()
{ jobs: [‘job1’, ‘job2’, ‘jobs3’] }
~ pykins jobs list
{ jobs: [‘job1’, ‘job2’, ‘jobs3’ }
Python
API
CL
I
Example #2 - get plugins
>>> j.get_plugins(version=True,
installed=True)
{ plugins: [
{‘name’: ‘LDAP’, ‘version’: 0.0.1, installed=True},
{‘name’: ‘Git’, ‘version’: 2.3.7, installed=True},
… ] }
~ pykins plugin list --format flat
LDAP
Git
Python
API
CL
I
Example #3 - Active Jobs
>>> j.get_non_active_jobs(days=200)
{ jobs: [‘job5, ‘job16’] }
~ pykins job list non-active --days 20 --simple
job51
job62
Python
API
CL
I
Jenkins api

More Related Content

PDF
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
PPTX
Jenkins tutorial
PPSX
CI-CD Jenkins, GitHub Actions, Tekton
PDF
Jenkins Pipeline Tutorial | Continuous Delivery Pipeline Using Jenkins | DevO...
PPTX
BitBucket presentation
PDF
Introduction to GitHub Actions
PPT
Jenkins Overview
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
Jenkins tutorial
CI-CD Jenkins, GitHub Actions, Tekton
Jenkins Pipeline Tutorial | Continuous Delivery Pipeline Using Jenkins | DevO...
BitBucket presentation
Introduction to GitHub Actions
Jenkins Overview

What's hot (20)

PDF
Automation with ansible
PPTX
Introduction to Gitlab | Gitlab 101 | Training Session
PPTX
GitLab.pptx
PDF
DevOps with GitHub Actions
PPTX
Github in Action
PDF
Introduction to Docker Compose
PDF
Ansible Introduction
PPTX
Jenkins CI
PDF
Introduction to Git
PPTX
CI/CD with GitHub Actions
PDF
Git training v10
PDF
CICD using jenkins and Nomad
PPTX
K8s security best practices
PDF
Hacking Jenkins
PPT
Git basic
PDF
Jenkins Pipelines
PPTX
CICD with Jenkins
PDF
Git real slides
PPTX
Git & GitLab
PPTX
Introduce to Git and Jenkins
Automation with ansible
Introduction to Gitlab | Gitlab 101 | Training Session
GitLab.pptx
DevOps with GitHub Actions
Github in Action
Introduction to Docker Compose
Ansible Introduction
Jenkins CI
Introduction to Git
CI/CD with GitHub Actions
Git training v10
CICD using jenkins and Nomad
K8s security best practices
Hacking Jenkins
Git basic
Jenkins Pipelines
CICD with Jenkins
Git real slides
Git & GitLab
Introduce to Git and Jenkins
Ad

Similar to Jenkins api (20)

PPTX
Webinar: AngularJS and the WordPress REST API
PPTX
Webinar: AngularJS and the WordPress REST API
PDF
Django 1.10.3 Getting started
PPTX
Elasticsearch an overview
PDF
Gae Meets Django
PDF
Java on Google App engine
PDF
Ejb3 Struts Tutorial En
PDF
Ejb3 Struts Tutorial En
PDF
AngularJS application architecture
KEY
Introduction to Django
PDF
Google app-engine-with-python
KEY
Introducing the Seneca MVP framework for Node.js
KEY
20120816 nodejsdublin
PDF
Introduction to Django
PDF
Python RESTful webservices with Python: Flask and Django solutions
PDF
Backbone.js
PDF
Sprint 69
PDF
N hidden gems in forge (as of may '17)
PDF
Introduction to App Engine Development
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
Django 1.10.3 Getting started
Elasticsearch an overview
Gae Meets Django
Java on Google App engine
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial En
AngularJS application architecture
Introduction to Django
Google app-engine-with-python
Introducing the Seneca MVP framework for Node.js
20120816 nodejsdublin
Introduction to Django
Python RESTful webservices with Python: Flask and Django solutions
Backbone.js
Sprint 69
N hidden gems in forge (as of may '17)
Introduction to App Engine Development
Ad

Recently uploaded (20)

PDF
Advancing precision in air quality forecasting through machine learning integ...
PDF
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
DOCX
search engine optimization ppt fir known well about this
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PPTX
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
PDF
Statistics on Ai - sourced from AIPRM.pdf
PDF
The influence of sentiment analysis in enhancing early warning system model f...
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PPTX
Internet of Everything -Basic concepts details
PDF
Data Virtualization in Action: Scaling APIs and Apps with FME
PPTX
Configure Apache Mutual Authentication
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PPTX
MuleSoft-Compete-Deck for midddleware integrations
PDF
Comparative analysis of machine learning models for fake news detection in so...
DOCX
Basics of Cloud Computing - Cloud Ecosystem
PPTX
Custom Battery Pack Design Considerations for Performance and Safety
PPTX
AI-driven Assurance Across Your End-to-end Network With ThousandEyes
Advancing precision in air quality forecasting through machine learning integ...
INTERSPEECH 2025 「Recent Advances and Future Directions in Voice Conversion」
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Rapid Prototyping: A lecture on prototyping techniques for interface design
search engine optimization ppt fir known well about this
Consumable AI The What, Why & How for Small Teams.pdf
GROUP4NURSINGINFORMATICSREPORT-2 PRESENTATION
Statistics on Ai - sourced from AIPRM.pdf
The influence of sentiment analysis in enhancing early warning system model f...
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
Internet of Everything -Basic concepts details
Data Virtualization in Action: Scaling APIs and Apps with FME
Configure Apache Mutual Authentication
sbt 2.0: go big (Scala Days 2025 edition)
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
MuleSoft-Compete-Deck for midddleware integrations
Comparative analysis of machine learning models for fake news detection in so...
Basics of Cloud Computing - Cloud Ecosystem
Custom Battery Pack Design Considerations for Performance and Safety
AI-driven Assurance Across Your End-to-end Network With ThousandEyes

Jenkins api

  • 2. Agenda ● Jenkins API ○ Overview ○ How to use ○ Examples ○ The ugly side ● Pykins ○ Overview ○ Examples
  • 3. Jenkins API overview● REST API ● Several data formats ○ XML ○ JSON ○ Python ● Retrieve Data ○ Jobs, Builds, Plugins, Nodes ● Actions ○ Trigger Jobs, Update Plugins Python?
  • 4. Why using Jenkis API? ● Dashboard ● Scripts ● Pull the specific data you need ● Jenkins UI is bad for your health
  • 5. Using Jenkins API ● Add ‘/api’ to Jenkins URL ○ https://my_jenkins/api ○ General permanent description + relevant documentation to the endpoint of your URL
  • 6. ● https://my_jenkins/job/my_job/api ● Add /api/json or /api/xml to get the actual data ○ Same data, different formats ○ There is a link at the the bottom of each page in Jenkins UI ● Next, examples! :)
  • 7. Example #1 - Baby Steps https://<jenkins_server>/api/json ● Master server ● Jobs ● Views {"_class":"hudson.model.Hudson","assignedLab els":[{}],"mode":"NORMAL","nodeDescription":"t he master Jenkins node","nodeName":"","numExecutors":2,"descri ption":null,"jobs":[{"_class":"org.jenkinsci.plu gins.workflow.job.WorkflowJob","name":"ov b-poc","url":"http://X/job/ovb- poc/","color":"red"},{"_class":"org.jenkinsci. plugins.workflow.job.WorkflowJob","name": "bla-poc","url":"http://X/job/bla- poc/","color":"blue"},...
  • 8. Example #2 - Depth https://<jenkins_server>/api/json?depth=1 ● Depth = 1 -> Description, Builds, Health report ● Depth = 2 -> SCM changes, artificats ● ... ● Depth = 10
  • 9. Example #3 - Tree https://<jenkins_server>/api/json?tree=jobs[name] ● tree=key[field1, field2, field3, subkey[subfield1, subfield2]] ● Elements and sub-elements of a tree you want to get ● Nested as required {"_class":"org.jenkinsci.plugins.workflow.job.WorkflowJob","name":"my_job"},{"_clas s":"org.jenkinsci.plugins.workflow.job.WorkflowJob","name":"Z- job"},{"_class":"org.jenkinsci.plugins.workflow.job.WorkflowJob","name":"Y- job"},{"_class":"org.jenkinsci.plugins.workflow.job.WorkflowJob","name":"X-job"}, ...
  • 10. Example #4 - Tree with subkeys https://<my_j>/api/json?tree=jobs[name,lastBuild[result,changeSet[items[author]]]] {"_class":"hudson.model.FreeStyleProject","name":"export-results-to-polarion- poc""lastBuild":{"_class":"hudson.model.FreeStyleBuild",,"result":"FAILURE","chang eSet":{"_class":"hudson.plugins.git.GitChangeSetList","items":[]}}}
  • 11. The ugly side of Jenkins API ● http://my_jenkins/api/json?kowabunga will work just fine ● https://<jenkins_server>/api/json?depth=20 is the easiest way to kill a Jenkins server ● Documentation
  • 12. Python Libraries ● python-jenkins ○ OpenStack project ● Jenkinsapi ○ Maintained by pycontribs ○ More active at this point of time
  • 13. Pykins ● Both Python API and CLI for Jenkins in one package! ● Custom calls support ● Additional functionality to Jenkins ● Maintained by couple of companies
  • 14. Example #1 - get jobs >>> j = pykins.Jenkins(“http://my_jenkins”) >>> j.get_jobs() { jobs: [‘job1’, ‘job2’, ‘jobs3’] } ~ pykins jobs list { jobs: [‘job1’, ‘job2’, ‘jobs3’ } Python API CL I
  • 15. Example #2 - get plugins >>> j.get_plugins(version=True, installed=True) { plugins: [ {‘name’: ‘LDAP’, ‘version’: 0.0.1, installed=True}, {‘name’: ‘Git’, ‘version’: 2.3.7, installed=True}, … ] } ~ pykins plugin list --format flat LDAP Git Python API CL I
  • 16. Example #3 - Active Jobs >>> j.get_non_active_jobs(days=200) { jobs: [‘job5, ‘job16’] } ~ pykins job list non-active --days 20 --simple job51 job62 Python API CL I