SlideShare a Scribd company logo
1 of 17
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

What's hot

Cypress - Best Practices
Cypress - Best PracticesCypress - Best Practices
Cypress - Best PracticesBrian Mann
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
 
Selenium with Cucumber
Selenium  with Cucumber Selenium  with Cucumber
Selenium with Cucumber Knoldus Inc.
 
BDD WITH CUCUMBER AND JAVA
BDD WITH CUCUMBER AND JAVABDD WITH CUCUMBER AND JAVA
BDD WITH CUCUMBER AND JAVASrinivas Katakam
 
Automation test framework with cucumber – BDD
Automation test framework with cucumber – BDDAutomation test framework with cucumber – BDD
Automation test framework with cucumber – BDD123abcda
 
ATLAS Automation POC
ATLAS Automation POCATLAS Automation POC
ATLAS Automation POCaakashmc
 
Selenium Architecture
Selenium ArchitectureSelenium Architecture
Selenium Architecturerohitnayak
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An IntroductionSam Brannen
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Deepak Singhvi
 
GitHub Actions in action
GitHub Actions in actionGitHub Actions in action
GitHub Actions in actionOleksii Holub
 
Selenium Grid
Selenium GridSelenium Grid
Selenium Gridnirvdrum
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET CoreAvanade Nederland
 
MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )Ahmed Emad
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of AngularKnoldus Inc.
 
채팅서버의 부하 분산 사례
채팅서버의 부하 분산 사례채팅서버의 부하 분산 사례
채팅서버의 부하 분산 사례John Kim
 

What's hot (20)

Cypress - Best Practices
Cypress - Best PracticesCypress - Best Practices
Cypress - Best Practices
 
Nunit
NunitNunit
Nunit
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Selenium with Cucumber
Selenium  with Cucumber Selenium  with Cucumber
Selenium with Cucumber
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
BDD WITH CUCUMBER AND JAVA
BDD WITH CUCUMBER AND JAVABDD WITH CUCUMBER AND JAVA
BDD WITH CUCUMBER AND JAVA
 
Jenkins tutorial
Jenkins tutorialJenkins tutorial
Jenkins tutorial
 
Automation test framework with cucumber – BDD
Automation test framework with cucumber – BDDAutomation test framework with cucumber – BDD
Automation test framework with cucumber – BDD
 
ATLAS Automation POC
ATLAS Automation POCATLAS Automation POC
ATLAS Automation POC
 
Selenium Architecture
Selenium ArchitectureSelenium Architecture
Selenium Architecture
 
Testing with Spring: An Introduction
Testing with Spring: An IntroductionTesting with Spring: An Introduction
Testing with Spring: An Introduction
 
Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.Testing and Mocking Object - The Art of Mocking.
Testing and Mocking Object - The Art of Mocking.
 
QSpiders - Automation using Selenium
QSpiders - Automation using SeleniumQSpiders - Automation using Selenium
QSpiders - Automation using Selenium
 
GitHub Actions in action
GitHub Actions in actionGitHub Actions in action
GitHub Actions in action
 
Selenium Grid
Selenium GridSelenium Grid
Selenium Grid
 
Introduction to ASP.NET Core
Introduction to ASP.NET CoreIntroduction to ASP.NET Core
Introduction to ASP.NET Core
 
MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )MVVM ( Model View ViewModel )
MVVM ( Model View ViewModel )
 
Building blocks of Angular
Building blocks of AngularBuilding blocks of Angular
Building blocks of Angular
 
채팅서버의 부하 분산 사례
채팅서버의 부하 분산 사례채팅서버의 부하 분산 사례
채팅서버의 부하 분산 사례
 
test_automation_POC
test_automation_POCtest_automation_POC
test_automation_POC
 

Similar to Jenkins api

Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWP Engine
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWP Engine UK
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting startedMoniaJ
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overviewAmit Juneja
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Java on Google App engine
Java on Google App engineJava on Google App engine
Java on Google App engineMichael Parker
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial EnAnkur Dongre
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architectureGabriele Falace
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJames Casey
 
Google app-engine-with-python
Google app-engine-with-pythonGoogle app-engine-with-python
Google app-engine-with-pythonDeepak Garg
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsRichard Rodger
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsSolution4Future
 
N hidden gems in forge (as of may '17)
N hidden gems in forge (as of may '17)N hidden gems in forge (as of may '17)
N hidden gems in forge (as of may '17)Woonsan Ko
 
Introduction to App Engine Development
Introduction to App Engine DevelopmentIntroduction to App Engine Development
Introduction to App Engine DevelopmentRon Reiter
 

Similar to Jenkins api (20)

Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 
Webinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST APIWebinar: AngularJS and the WordPress REST API
Webinar: AngularJS and the WordPress REST API
 
Django 1.10.3 Getting started
Django 1.10.3 Getting startedDjango 1.10.3 Getting started
Django 1.10.3 Getting started
 
Elasticsearch an overview
Elasticsearch   an overviewElasticsearch   an overview
Elasticsearch an overview
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Java on Google App engine
Java on Google App engineJava on Google App engine
Java on Google App engine
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
Ejb3 Struts Tutorial En
Ejb3 Struts Tutorial EnEjb3 Struts Tutorial En
Ejb3 Struts Tutorial En
 
AngularJS application architecture
AngularJS application architectureAngularJS application architecture
AngularJS application architecture
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Google app-engine-with-python
Google app-engine-with-pythonGoogle app-engine-with-python
Google app-engine-with-python
 
Introducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.jsIntroducing the Seneca MVP framework for Node.js
Introducing the Seneca MVP framework for Node.js
 
20120816 nodejsdublin
20120816 nodejsdublin20120816 nodejsdublin
20120816 nodejsdublin
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Python RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutionsPython RESTful webservices with Python: Flask and Django solutions
Python RESTful webservices with Python: Flask and Django solutions
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Gwt.create
Gwt.createGwt.create
Gwt.create
 
Sprint 69
Sprint 69Sprint 69
Sprint 69
 
N hidden gems in forge (as of may '17)
N hidden gems in forge (as of may '17)N hidden gems in forge (as of may '17)
N hidden gems in forge (as of may '17)
 
Introduction to App Engine Development
Introduction to App Engine DevelopmentIntroduction to App Engine Development
Introduction to App Engine Development
 

Recently uploaded

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Recently uploaded (20)

Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

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