際際滷

際際滷Share a Scribd company logo
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
Ad

Recommended

CodeScene: Get Deep Insights into Your (Clojure) Code [Clojure Vienna meetup ...
CodeScene: Get Deep Insights into Your (Clojure) Code [Clojure Vienna meetup ...
Juraj Martinka
Seguran巽a da Informa巽達o - Aula 4 - Malwares
Cleber Fonseca
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Continuous Delivery in Enterprise Environments using Docker, Ansible and Jenkins
Marcel Birkner
An intro to Docker, Terraform, and Amazon ECS
An intro to Docker, Terraform, and Amazon ECS
Yevgeniy Brikman
Monitoring kubernetes wwith prometheus and grafana azure singapore - 19 aug...
Monitoring kubernetes wwith prometheus and grafana azure singapore - 19 aug...
Nilesh Gule
Google Cloud Composer
Pierre Coste
Dapr - A 10x Developer Framework for Any Language
Dapr - A 10x Developer Framework for Any Language
Bilgin Ibryam
Semin叩rio Computa巽達o em Nuvem
Leandro Nunes
Introduction to Kubernetes Security
Introduction to Kubernetes Security
All Things Open
語 麹襯 覦 企
語 麹襯 覦 企
Seung-won CHAE
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Andrew Bayer
Accessibility with OutSystems
Accessibility with OutSystems
Bruno Marcelino
Deploying Azure DevOps using Terraform
Deploying Azure DevOps using Terraform
Adin Ermie
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
Tomasz Cholewa
Cilium - overview and recent updates
Cilium - overview and recent updates
Michal Rostecki
Computa巽達o em nuvem
Claudin辿ia da Silva
Introdu巽達o aos sistemas operacionais cap 01 (i unidade)
Faculdade Mater Christi
Introduction to DevOps
Introduction to DevOps
OCTO Technology
Blockchain : Decentralized Application Development (Turkish)
Blockchain : Decentralized Application Development (Turkish)
Cihan zhan
際際滷s 29-07-2017
際際滷s 29-07-2017
Soumyak Bhattacharyya
Intro to Pentesting Jenkins
Intro to Pentesting Jenkins
Brian Hysell
Bringing Jenkins Remote Access API To The Masses
Bringing Jenkins Remote Access API To The Masses
Cliffano Subagio
Hacking Jenkins
Hacking Jenkins
Miro Cupak
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Noah Sussman
JUC Europe 2015: Hey! What Did We Just Release?
JUC Europe 2015: Hey! What Did We Just Release?
CloudBees
Using Jenkins XML API
Using Jenkins XML API
Anton Weiss
Jenkins.pptx
Jenkins.pptx
rfojdar
Jenkins 101: Continuos Integration with Jenkins
Jenkins 101: Continuos Integration with Jenkins
All Things Open
Jenkins automation
Jenkins automation
Aleksey Maksimov
Introduction to jenkins
Introduction to jenkins
Krish

More Related Content

What's hot (11)

Introduction to Kubernetes Security
Introduction to Kubernetes Security
All Things Open
語 麹襯 覦 企
語 麹襯 覦 企
Seung-won CHAE
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Andrew Bayer
Accessibility with OutSystems
Accessibility with OutSystems
Bruno Marcelino
Deploying Azure DevOps using Terraform
Deploying Azure DevOps using Terraform
Adin Ermie
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
Tomasz Cholewa
Cilium - overview and recent updates
Cilium - overview and recent updates
Michal Rostecki
Computa巽達o em nuvem
Claudin辿ia da Silva
Introdu巽達o aos sistemas operacionais cap 01 (i unidade)
Faculdade Mater Christi
Introduction to DevOps
Introduction to DevOps
OCTO Technology
Blockchain : Decentralized Application Development (Turkish)
Blockchain : Decentralized Application Development (Turkish)
Cihan zhan
Introduction to Kubernetes Security
Introduction to Kubernetes Security
All Things Open
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Andrew Bayer
Accessibility with OutSystems
Accessibility with OutSystems
Bruno Marcelino
Deploying Azure DevOps using Terraform
Deploying Azure DevOps using Terraform
Adin Ermie
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
Kubernetes or OpenShift - choosing your container platform for Dev and Ops
Tomasz Cholewa
Cilium - overview and recent updates
Cilium - overview and recent updates
Michal Rostecki
Computa巽達o em nuvem
Claudin辿ia da Silva
Introdu巽達o aos sistemas operacionais cap 01 (i unidade)
Faculdade Mater Christi
Introduction to DevOps
Introduction to DevOps
OCTO Technology
Blockchain : Decentralized Application Development (Turkish)
Blockchain : Decentralized Application Development (Turkish)
Cihan zhan

Similar to Jenkins api (20)

際際滷s 29-07-2017
際際滷s 29-07-2017
Soumyak Bhattacharyya
Intro to Pentesting Jenkins
Intro to Pentesting Jenkins
Brian Hysell
Bringing Jenkins Remote Access API To The Masses
Bringing Jenkins Remote Access API To The Masses
Cliffano Subagio
Hacking Jenkins
Hacking Jenkins
Miro Cupak
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Noah Sussman
JUC Europe 2015: Hey! What Did We Just Release?
JUC Europe 2015: Hey! What Did We Just Release?
CloudBees
Using Jenkins XML API
Using Jenkins XML API
Anton Weiss
Jenkins.pptx
Jenkins.pptx
rfojdar
Jenkins 101: Continuos Integration with Jenkins
Jenkins 101: Continuos Integration with Jenkins
All Things Open
Jenkins automation
Jenkins automation
Aleksey Maksimov
Introduction to jenkins
Introduction to jenkins
Krish
Managing Jenkins with Python
Managing Jenkins with Python
Vijay Kumar Bagavath Singh
JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Je...
JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Je...
CloudBees
JenkinsMobi: Jenkins XML API for Mobile Applications
JenkinsMobi: Jenkins XML API for Mobile Applications
Luca Milanesio
Jenkinsconf Presentation - Advance jenkins management with multiple projects.
Jenkinsconf Presentation - Advance jenkins management with multiple projects.
Ohad Basan
Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.
ukasz Proszek
Continuous Integration using Jenkins with Python
Continuous Integration using Jenkins with Python
Inexture Solutions
Jenkins CI
Jenkins CI
Viyaan Jhiingade
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Alvin Huang
Jenkins talk at Silicon valley DevOps meetup
Jenkins talk at Silicon valley DevOps meetup
CloudBees
Intro to Pentesting Jenkins
Intro to Pentesting Jenkins
Brian Hysell
Bringing Jenkins Remote Access API To The Masses
Bringing Jenkins Remote Access API To The Masses
Cliffano Subagio
Hacking Jenkins
Hacking Jenkins
Miro Cupak
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Jenkins data mining on the command line - Jenkins User Conference NYC 2012
Noah Sussman
JUC Europe 2015: Hey! What Did We Just Release?
JUC Europe 2015: Hey! What Did We Just Release?
CloudBees
Using Jenkins XML API
Using Jenkins XML API
Anton Weiss
Jenkins.pptx
Jenkins.pptx
rfojdar
Jenkins 101: Continuos Integration with Jenkins
Jenkins 101: Continuos Integration with Jenkins
All Things Open
Introduction to jenkins
Introduction to jenkins
Krish
JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Je...
JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Je...
CloudBees
JenkinsMobi: Jenkins XML API for Mobile Applications
JenkinsMobi: Jenkins XML API for Mobile Applications
Luca Milanesio
Jenkinsconf Presentation - Advance jenkins management with multiple projects.
Jenkinsconf Presentation - Advance jenkins management with multiple projects.
Ohad Basan
Take control of your Jenkins jobs via job DSL.
Take control of your Jenkins jobs via job DSL.
ukasz Proszek
Continuous Integration using Jenkins with Python
Continuous Integration using Jenkins with Python
Inexture Solutions
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Alvin Huang
Jenkins talk at Silicon valley DevOps meetup
Jenkins talk at Silicon valley DevOps meetup
CloudBees
Ad

Recently uploaded (20)

Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
Mastering AI Workflows with FME by Mark Doring
Mastering AI Workflows with FME by Mark Doring
Safe Software
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Josef Weingand
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
Mastering AI Workflows with FME by Mark Doring
Mastering AI Workflows with FME by Mark Doring
Safe Software
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Josef Weingand
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
Quantum AI: Where Impossible Becomes Probable
Quantum AI: Where Impossible Becomes Probable
Saikat Basu
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
Curietech AI in action - Accelerate MuleSoft development
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
Ad

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