SlideShare a Scribd company logo
#jenkinsconf
Orchestrating Your Jenkins Pipelines With
Python and Jenkins API
London, 23 & 24 June 2015
#jenkinsconf
whoami
Pradeepto Bhattacharya / @pradeepto
#jenkinsconf
Agenda
l
Why do we need this library?
l
Installation
l
Library Modules
l
Code Examples
l
Documentations
l
Q & A
#jenkinsconf
#jenkinsconf
The Motivation
#jenkinsconf
Why?
l
Sometimes you want more control over how you want run your
jobs.
l
It is true that you have many plugins to so many things like -
copy artifacts, run child jobs etc. No doubt about it.
l
But then there are times you have to develop systems or CI
pipelines where you need more fine grained control.
l
Thanks to the developers of Jenkins, there is an excellent
REST API.
l
Open source being open source, some good dudes have
written a Python library encapsulating the REST API
l
This talk is about this library and what can we do with it.
#jenkinsconf
#jenkinsconf
Installation
#jenkinsconf
Installation
l
pip install jenkinsapi
l
easy_install jenkinsapi
l
sudo apt-get install python-jenkinsapi
l
Note : There are other similar libraries. I found this one best for all my use cases. It definitely was
the most exhaustive.
#jenkinsconf
#jenkinsconf
Modules and Code
#jenkinsconf
Main modules
l
Jenkins : The Jenkins instance
l
Job(s) : Represents Jenkins jobs.
l
User API : Consists of helpful high-level functions
l
Build : This module encapsulates the single run of a
Jenkins job
l
Artifact : Artifacts are created by Jenkins build. This
module encapsulates that.
l
Node : Encapsulates Jenkins Node
#jenkinsconf
Connect to Jenkins
l
from jenkinsapi.jenkins import Jenkins
l
def get_jenkins_instance():
l
return Jenkins('http://10.10.20.100:8080')
#jenkinsconf
Jobs
l
>>> jenkins = get_jenkins_instance()
l
>>> jenkins.keys()
l
>>> ['Beefy Job', 'Simple Job']
l
>>> jobs = jenkins.get_jobs()
l
>>> for job in jobs:
l
... print job
l
...
l
('Beefy Job', <jenkinsapi.job.Job Beefy Job>)
l
('Simple Job', <jenkinsapi.job.Job Simple Job>)
#jenkinsconf
Jobs
l
>>> job = jenkins.get_job('Simple Job')
l
>>> job.get_description()
l
'A very simple job'
l
>>> job.is_enabled()
l
True
l
>>> job.is_running()
l
False
l
>>> job.get_last_stable_buildnumber()
l
29
#jenkinsconf
Jobs
l
>>> job = jenkins.get_job('Beefy Job')
l
>>> job.get_last_failed_buildnumber()
l
3
l
>>> job.get_last_completed_build()
l
<jenkinsapi.build.Build Beefy Job #53>
l
>>> job.invoke()
l
<jenkinsapi.invocation.Invocation object at 0x7f0f75733050>
l
>>> job.is_running()
l
True
#jenkinsconf
Jobs
l
>>> job.get_scm_type()
l
'git'
l
>>> job.get_scm_branch()
l
['*/master']
l
>>> job.get_scm_url()
l
['http://github.com/jenkinsci/mesos-plugin']
#jenkinsconf
Jobs
l
>>> job.disable()
l
>>> job.is_enabled()
l
False
l
>>> job.enable()
l
>>> job.is_enabled()
l
True
#jenkinsconf
Jobs
l
'get_first_build', 'get_first_buildnumber', 'get_jenkins_obj', 'get_last_build',
'get_last_buildnumber', 'get_last_completed_build', 'get_last_completed_buildnumber',
'get_last_failed_buildnumber', 'get_last_good_build', 'get_last_good_buildnumber',
'get_last_stable_build', 'get_last_stable_buildnumber', 'get_next_build_number',
'get_params', 'get_params_list', 'get_revision_dict', 'get_scm_branch', 'get_scm_type',
'get_scm_url', 'get_upstream_job_names', 'get_upstream_jobs', 'has_queued_build',
'invoke', 'is_enabled', 'is_queued', 'is_queued_or_running', 'is_running'
#jenkinsconf
User API
l
from jenkinsapi.api import *
l
>>> get_latest_build('http://10.10.20.100:8080','Simple Job')
l
<jenkinsapi.build.Build Simple Job #29>
l
>>> get_latest_complete_build('http://10.10.20.100:8080','Beefy Job')
l
<jenkinsapi.build.Build Beefy Job #53>
#jenkinsconf
Build
l
>>> build = job.get_build(54)
l
>>> build.is_running()
l
True
l
>>> build.get_revision()
l
'b0c30d15b4c0ac55d003db7533c00e889f74891e'
l
>>> build.name
l
'Beefy Job #57'
l
>>> build.get_status()
l
'SUCCESS'
#jenkinsconf
Build
l
>>> build.get_console()
l
'Started by user anonymousnBuilding on master in workspace /var/lib/jenkins/workspace/Beefy
Jobn > git rev-parse --is-inside-work-tree # timeout=10nFetching changes from the remote Git
repositoryn > git config remote.origin.url http://github.com/jenkinsci/mesos-plugin #
timeout=10nFetching upstream changes from http://github.com/jenkinsci/mesos-pluginn > git
--version # timeout=10n > git -c core.askpass=true fetch --tags --progress
http://github.com/jenkinsci/mesos-plugin +refs/heads/*:refs/remotes/origin/*n > git rev-parse
refs/remotes/origin/master^{commit} # timeout=10n > git rev-parse
refs/remotes/origin/origin/master^{commit} # timeout=10nChecking out Revision
b0c30d15b4c0ac55d003db7533c00e889f74891e (refs/remotes/origin/master)n > git config
core.sparsecheckout # timeout=10n > git checkout -f
b0c30d15b4c0ac55d003db7533c00e889f74891en > git rev-list
b0c30d15b4c0ac55d003db7533c00e889f74891e # timeout=10n[Beefy Job] $ /bin/sh -xe
/tmp/hudson1394675615697321597.shn+ set -xn+ echo This job takes a lot of time and
consumes a lot of resources.nThis job takes a lot of time and consumes a lot of resources.n+
which pythonn/usr/bin/pythonn+ python --versionnPython 2.7.6n+ sleep 180n+ echo Done
building beefy job.nDone building beefy job.nFinished: SUCCESSn'
#jenkinsconf
Build
l
'block', 'block_until_complete', 'buildno', 'get_actions', 'get_artifact_dict', 'get_artifacts',
'get_console', 'get_data', 'get_downstream_builds', 'get_downstream_job_names',
'get_downstream_jobs', 'get_duration', 'get_jenkins_obj', 'get_master_build',
'get_master_build_number', 'get_master_job', 'get_master_job_name',
'get_matrix_runs', 'get_number', 'get_result_url', 'get_resultset', 'get_revision',
'get_revision_branch', 'get_status', 'get_timestamp', 'get_upstream_build',
'get_upstream_build_number', 'get_upstream_job', 'get_upstream_job_name',
'has_resultset', 'is_good', 'is_running'
#jenkinsconf
Artifacts
l
>>> job = jenkins.get_job('Simple Job')
l
>>> build = job.get_build(33)
l
>>> build.get_artifact_dict()
l
{'artifact.txt': <jenkinsapi.artifact.Artifact http://10.10.20.100:8080/job/Simple
%20Job/33/artifact/artifact.txt>}
l
>>> build.get_artifact_dict()['artifact.txt'].get_data()
l
'This is artifactn'
#jenkinsconf
Nodes
l
>>> for node in jenkins.get_nodes().keys():
l
... print node
l
...
l
master
l
Big
l
Small
l
>>> small.is_online()
l
True
#jenkinsconf
Plugins
l
>>> jenkins.get_plugins().keys()
l
['git-client', 'matrix-auth', 'mesos', 'maven-plugin', 'javadoc', 'external-monitor-job', 'ant',
'ssh-slaves', 'pam-auth', 'windows-slaves', 'git', 'scm-api', 'subversion', 'antisamy-
markup-formatter', 'ldap', 'junit', 'mailer', 'credentials', 'translation', 'ssh-credentials',
'matrix-project', 'cvs', 'script-security']
#jenkinsconf
Exceptions
l
This library comes with bunch of built-in exceptions. I highly
recommend you use them in your code and do stuff as you
want in case you catch those whilst running your CI pipelines.
l
JenkinsAPIException, UnknownJob, UnknownView,
UnknownNode, UnknownPlugin, NoBuildData, NoResults ...
#jenkinsconf
Other things you could ...
l
Create Jobs
l
Create Views
l
Monitor and query builds/jobs/nodes
l
Search and manipulate artifacts
#jenkinsconf
Documentation
l
Some (very few) of the modules are documented.
l
There are a few examples in documentation.
l
Great opportunity to contribute to this wonderful
library.
l
https://github.com/salimfadhley/jenkinsapi
#jenkinsconf
Questions?
pradeeptob@gmail.com
#jenkinsconf
Agenda
CloudBees and organisers of JUC Europe 2015
Contributors of Jenkins, Mesos, Mesos plugin
My Family
Kalpak, Shikha, Lenin
Girija and Rupali (my partners in CI related crimes)
#jenkinsconf
Please Share Your Feedback
• Did you find this session valuable?
• Please share your thoughts in the
• Jenkins User Conference Mobile App.
• Find the session in the app and click
• on the feedback area.

More Related Content

PDF
JUC Europe 2015: Jenkins-Based Continuous Integration for Heterogeneous Hardw...
PDF
JUC Europe 2015: Optimizing Your CI: Lessons Learned from a Successful Jenkin...
PDF
JUC Europe 2015: The Famous Cows of Cambridge: A Non-Standard Use Case for Je...
PDF
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and Maintenance
PDF
JUC Europe 2015: Hey! What Did We Just Release?
PDF
JUC Europe 2015: Jenkins Made Easy
PDF
From Virtual Machines to Containers
PDF
JUC Europe 2015: Enabling Continuous Delivery for Major Retailers
JUC Europe 2015: Jenkins-Based Continuous Integration for Heterogeneous Hardw...
JUC Europe 2015: Optimizing Your CI: Lessons Learned from a Successful Jenkin...
JUC Europe 2015: The Famous Cows of Cambridge: A Non-Standard Use Case for Je...
JUC Europe 2015: Scaling of Jenkins Pipeline Creation and Maintenance
JUC Europe 2015: Hey! What Did We Just Release?
JUC Europe 2015: Jenkins Made Easy
From Virtual Machines to Containers
JUC Europe 2015: Enabling Continuous Delivery for Major Retailers

What's hot (20)

PDF
JUC Europe 2015: Plugin Development with Gradle and Groovy
PDF
JUC Europe 2015: Continuous Integration and Distribution in the Cloud with DE...
PDF
JUC Europe 2015: Scaling Your Jenkins Master with Docker
PDF
JUC Europe 2015: Jenkins Pipeline for Continuous Delivery of Big Data Projects
PDF
JUC Europe 2015: Bringing CD at Cloud-Scale with Jenkins, Docker and "Tiger"
PDF
At Your Service: Using Jenkins in Operations
PDF
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
PPTX
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
ODP
Scaling your jenkins master with docker
PDF
Brujug Jenkins pipeline scalability
PPTX
Drupal Continuous Integration with Jenkins - The Basics
PPTX
Grooving with Jenkins
PDF
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
PDF
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
PDF
Let’s start Continuous Integration with jenkins
PPT
Jenkins Scriptler in 90mins
PPTX
Jenkins days workshop pipelines - Eric Long
PDF
Jenkins Best Practices
PPTX
Jenkins tutorial
PDF
Dockercon2015 bamboo
JUC Europe 2015: Plugin Development with Gradle and Groovy
JUC Europe 2015: Continuous Integration and Distribution in the Cloud with DE...
JUC Europe 2015: Scaling Your Jenkins Master with Docker
JUC Europe 2015: Jenkins Pipeline for Continuous Delivery of Big Data Projects
JUC Europe 2015: Bringing CD at Cloud-Scale with Jenkins, Docker and "Tiger"
At Your Service: Using Jenkins in Operations
Managing Jenkins with Jenkins (Jenkins User Conference Palo Alto, 2013)
Seven Habits of Highly Effective Jenkins Users (2014 edition!)
Scaling your jenkins master with docker
Brujug Jenkins pipeline scalability
Drupal Continuous Integration with Jenkins - The Basics
Grooving with Jenkins
Jenkins vs. AWS CodePipeline (AWS User Group Berlin)
An Open-Source Chef Cookbook CI/CD Implementation Using Jenkins Pipelines
Let’s start Continuous Integration with jenkins
Jenkins Scriptler in 90mins
Jenkins days workshop pipelines - Eric Long
Jenkins Best Practices
Jenkins tutorial
Dockercon2015 bamboo
Ad

Similar to JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Jenkins API (20)

PDF
Jenkins automation
PDF
Managing Jenkins with Python
PDF
Continuous Integration using Jenkins with Python
PDF
Take control of your Jenkins jobs via job DSL.
PDF
Jenkins-CI
PDF
Slides 29-07-2017
PPTX
Jenkins api
PDF
Configuration as Code in Jenkins. What's new? Nov 2016
PPTX
Moving from Jenkins 1 to 2 declarative pipeline adventures
PPTX
Jenkins CI
PDF
JUC Europe 2015: Configuration as Code: The Job DSL Plugin
PDF
Hacking Jenkins
PDF
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
PPTX
Pipeline as code - new feature in Jenkins 2
PDF
Juc boston2014.pptx
PPTX
2019 Chef InSpec Jumpstart Part 2 of 2
PDF
Continuous Integration/Deployment with Docker and Jenkins
PDF
Practical continuous quality gates for development process
PDF
Jenkins 101: Getting Started
PDF
JUC Europe 2015: A Reproducible Build Environment with Jenkins
Jenkins automation
Managing Jenkins with Python
Continuous Integration using Jenkins with Python
Take control of your Jenkins jobs via job DSL.
Jenkins-CI
Slides 29-07-2017
Jenkins api
Configuration as Code in Jenkins. What's new? Nov 2016
Moving from Jenkins 1 to 2 declarative pipeline adventures
Jenkins CI
JUC Europe 2015: Configuration as Code: The Job DSL Plugin
Hacking Jenkins
Codifying the Build and Release Process with a Jenkins Pipeline Shared Library
Pipeline as code - new feature in Jenkins 2
Juc boston2014.pptx
2019 Chef InSpec Jumpstart Part 2 of 2
Continuous Integration/Deployment with Docker and Jenkins
Practical continuous quality gates for development process
Jenkins 101: Getting Started
JUC Europe 2015: A Reproducible Build Environment with Jenkins
Ad

More from CloudBees (16)

PDF
JUC Europe 2015: Multi-Node Environment as a Jenkins Slave (Compound-Slave)
PDF
JUC Europe 2015: From Virtual Machines to Containers: Achieving Continuous In...
PDF
JUC Europe 2015: Making Strides towards Enterprise-Scale DevOps...with Jenkin...
PDF
JUC Europe 2015: Evolving the Jenkins UI
PDF
JUC Europe 2015: Using Infrastructure Nodes Wisely With Jenkins and Apache Mesos
PDF
JUC Europe 2015: How to Optimize Automated Testing with Everyone's Favorite B...
PDF
JUC 2015 - Keynote Address and Opening Remarks by Kohsuke Kawaguchi, Founder,...
PDF
Pimp your jenkins platform with docker - Devops.com 2015/11
PDF
Analyze This! CloudBees Jenkins Cluster Operations and Analytics
PDF
Jenkins Workflow Webinar - Dec 10, 2014
PDF
CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)
PDF
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
PDF
From Continuous Integration to Continuous Delivery with Jenkins - javaland.de...
PDF
Rethinking Application Design for the Cloud
PPTX
The Fall of Giants
PPTX
Getting Started with Platform-as-a-Service
JUC Europe 2015: Multi-Node Environment as a Jenkins Slave (Compound-Slave)
JUC Europe 2015: From Virtual Machines to Containers: Achieving Continuous In...
JUC Europe 2015: Making Strides towards Enterprise-Scale DevOps...with Jenkin...
JUC Europe 2015: Evolving the Jenkins UI
JUC Europe 2015: Using Infrastructure Nodes Wisely With Jenkins and Apache Mesos
JUC Europe 2015: How to Optimize Automated Testing with Everyone's Favorite B...
JUC 2015 - Keynote Address and Opening Remarks by Kohsuke Kawaguchi, Founder,...
Pimp your jenkins platform with docker - Devops.com 2015/11
Analyze This! CloudBees Jenkins Cluster Operations and Analytics
Jenkins Workflow Webinar - Dec 10, 2014
CI and CD Across the Enterprise with Jenkins (devops.com Nov 2014)
Pimp your Continuous Delivery Pipeline with Jenkins workflow (W-JAX 14)
From Continuous Integration to Continuous Delivery with Jenkins - javaland.de...
Rethinking Application Design for the Cloud
The Fall of Giants
Getting Started with Platform-as-a-Service

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Machine learning based COVID-19 study performance prediction
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPTX
A Presentation on Artificial Intelligence
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Modernizing your data center with Dell and AMD
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Cloud computing and distributed systems.
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Approach and Philosophy of On baking technology
Spectral efficient network and resource selection model in 5G networks
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction
The AUB Centre for AI in Media Proposal.docx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Review of recent advances in non-invasive hemoglobin estimation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
A Presentation on Artificial Intelligence
The Rise and Fall of 3GPP – Time for a Sabbatical?
Modernizing your data center with Dell and AMD
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Electronic commerce courselecture one. Pdf
NewMind AI Monthly Chronicles - July 2025
Empathic Computing: Creating Shared Understanding
Cloud computing and distributed systems.
“AI and Expert System Decision Support & Business Intelligence Systems”
Approach and Philosophy of On baking technology

JUC Europe 2015: Orchestrating Your Pipelines with Jenkins, Python and the Jenkins API

  • 1. #jenkinsconf Orchestrating Your Jenkins Pipelines With Python and Jenkins API London, 23 & 24 June 2015
  • 3. #jenkinsconf Agenda l Why do we need this library? l Installation l Library Modules l Code Examples l Documentations l Q & A
  • 5. #jenkinsconf Why? l Sometimes you want more control over how you want run your jobs. l It is true that you have many plugins to so many things like - copy artifacts, run child jobs etc. No doubt about it. l But then there are times you have to develop systems or CI pipelines where you need more fine grained control. l Thanks to the developers of Jenkins, there is an excellent REST API. l Open source being open source, some good dudes have written a Python library encapsulating the REST API l This talk is about this library and what can we do with it.
  • 7. #jenkinsconf Installation l pip install jenkinsapi l easy_install jenkinsapi l sudo apt-get install python-jenkinsapi l Note : There are other similar libraries. I found this one best for all my use cases. It definitely was the most exhaustive.
  • 9. #jenkinsconf Main modules l Jenkins : The Jenkins instance l Job(s) : Represents Jenkins jobs. l User API : Consists of helpful high-level functions l Build : This module encapsulates the single run of a Jenkins job l Artifact : Artifacts are created by Jenkins build. This module encapsulates that. l Node : Encapsulates Jenkins Node
  • 10. #jenkinsconf Connect to Jenkins l from jenkinsapi.jenkins import Jenkins l def get_jenkins_instance(): l return Jenkins('http://10.10.20.100:8080')
  • 11. #jenkinsconf Jobs l >>> jenkins = get_jenkins_instance() l >>> jenkins.keys() l >>> ['Beefy Job', 'Simple Job'] l >>> jobs = jenkins.get_jobs() l >>> for job in jobs: l ... print job l ... l ('Beefy Job', <jenkinsapi.job.Job Beefy Job>) l ('Simple Job', <jenkinsapi.job.Job Simple Job>)
  • 12. #jenkinsconf Jobs l >>> job = jenkins.get_job('Simple Job') l >>> job.get_description() l 'A very simple job' l >>> job.is_enabled() l True l >>> job.is_running() l False l >>> job.get_last_stable_buildnumber() l 29
  • 13. #jenkinsconf Jobs l >>> job = jenkins.get_job('Beefy Job') l >>> job.get_last_failed_buildnumber() l 3 l >>> job.get_last_completed_build() l <jenkinsapi.build.Build Beefy Job #53> l >>> job.invoke() l <jenkinsapi.invocation.Invocation object at 0x7f0f75733050> l >>> job.is_running() l True
  • 14. #jenkinsconf Jobs l >>> job.get_scm_type() l 'git' l >>> job.get_scm_branch() l ['*/master'] l >>> job.get_scm_url() l ['http://github.com/jenkinsci/mesos-plugin']
  • 16. #jenkinsconf Jobs l 'get_first_build', 'get_first_buildnumber', 'get_jenkins_obj', 'get_last_build', 'get_last_buildnumber', 'get_last_completed_build', 'get_last_completed_buildnumber', 'get_last_failed_buildnumber', 'get_last_good_build', 'get_last_good_buildnumber', 'get_last_stable_build', 'get_last_stable_buildnumber', 'get_next_build_number', 'get_params', 'get_params_list', 'get_revision_dict', 'get_scm_branch', 'get_scm_type', 'get_scm_url', 'get_upstream_job_names', 'get_upstream_jobs', 'has_queued_build', 'invoke', 'is_enabled', 'is_queued', 'is_queued_or_running', 'is_running'
  • 17. #jenkinsconf User API l from jenkinsapi.api import * l >>> get_latest_build('http://10.10.20.100:8080','Simple Job') l <jenkinsapi.build.Build Simple Job #29> l >>> get_latest_complete_build('http://10.10.20.100:8080','Beefy Job') l <jenkinsapi.build.Build Beefy Job #53>
  • 18. #jenkinsconf Build l >>> build = job.get_build(54) l >>> build.is_running() l True l >>> build.get_revision() l 'b0c30d15b4c0ac55d003db7533c00e889f74891e' l >>> build.name l 'Beefy Job #57' l >>> build.get_status() l 'SUCCESS'
  • 19. #jenkinsconf Build l >>> build.get_console() l 'Started by user anonymousnBuilding on master in workspace /var/lib/jenkins/workspace/Beefy Jobn > git rev-parse --is-inside-work-tree # timeout=10nFetching changes from the remote Git repositoryn > git config remote.origin.url http://github.com/jenkinsci/mesos-plugin # timeout=10nFetching upstream changes from http://github.com/jenkinsci/mesos-pluginn > git --version # timeout=10n > git -c core.askpass=true fetch --tags --progress http://github.com/jenkinsci/mesos-plugin +refs/heads/*:refs/remotes/origin/*n > git rev-parse refs/remotes/origin/master^{commit} # timeout=10n > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10nChecking out Revision b0c30d15b4c0ac55d003db7533c00e889f74891e (refs/remotes/origin/master)n > git config core.sparsecheckout # timeout=10n > git checkout -f b0c30d15b4c0ac55d003db7533c00e889f74891en > git rev-list b0c30d15b4c0ac55d003db7533c00e889f74891e # timeout=10n[Beefy Job] $ /bin/sh -xe /tmp/hudson1394675615697321597.shn+ set -xn+ echo This job takes a lot of time and consumes a lot of resources.nThis job takes a lot of time and consumes a lot of resources.n+ which pythonn/usr/bin/pythonn+ python --versionnPython 2.7.6n+ sleep 180n+ echo Done building beefy job.nDone building beefy job.nFinished: SUCCESSn'
  • 20. #jenkinsconf Build l 'block', 'block_until_complete', 'buildno', 'get_actions', 'get_artifact_dict', 'get_artifacts', 'get_console', 'get_data', 'get_downstream_builds', 'get_downstream_job_names', 'get_downstream_jobs', 'get_duration', 'get_jenkins_obj', 'get_master_build', 'get_master_build_number', 'get_master_job', 'get_master_job_name', 'get_matrix_runs', 'get_number', 'get_result_url', 'get_resultset', 'get_revision', 'get_revision_branch', 'get_status', 'get_timestamp', 'get_upstream_build', 'get_upstream_build_number', 'get_upstream_job', 'get_upstream_job_name', 'has_resultset', 'is_good', 'is_running'
  • 21. #jenkinsconf Artifacts l >>> job = jenkins.get_job('Simple Job') l >>> build = job.get_build(33) l >>> build.get_artifact_dict() l {'artifact.txt': <jenkinsapi.artifact.Artifact http://10.10.20.100:8080/job/Simple %20Job/33/artifact/artifact.txt>} l >>> build.get_artifact_dict()['artifact.txt'].get_data() l 'This is artifactn'
  • 22. #jenkinsconf Nodes l >>> for node in jenkins.get_nodes().keys(): l ... print node l ... l master l Big l Small l >>> small.is_online() l True
  • 23. #jenkinsconf Plugins l >>> jenkins.get_plugins().keys() l ['git-client', 'matrix-auth', 'mesos', 'maven-plugin', 'javadoc', 'external-monitor-job', 'ant', 'ssh-slaves', 'pam-auth', 'windows-slaves', 'git', 'scm-api', 'subversion', 'antisamy- markup-formatter', 'ldap', 'junit', 'mailer', 'credentials', 'translation', 'ssh-credentials', 'matrix-project', 'cvs', 'script-security']
  • 24. #jenkinsconf Exceptions l This library comes with bunch of built-in exceptions. I highly recommend you use them in your code and do stuff as you want in case you catch those whilst running your CI pipelines. l JenkinsAPIException, UnknownJob, UnknownView, UnknownNode, UnknownPlugin, NoBuildData, NoResults ...
  • 25. #jenkinsconf Other things you could ... l Create Jobs l Create Views l Monitor and query builds/jobs/nodes l Search and manipulate artifacts
  • 26. #jenkinsconf Documentation l Some (very few) of the modules are documented. l There are a few examples in documentation. l Great opportunity to contribute to this wonderful library. l https://github.com/salimfadhley/jenkinsapi
  • 28. #jenkinsconf Agenda CloudBees and organisers of JUC Europe 2015 Contributors of Jenkins, Mesos, Mesos plugin My Family Kalpak, Shikha, Lenin Girija and Rupali (my partners in CI related crimes)
  • 29. #jenkinsconf Please Share Your Feedback • Did you find this session valuable? • Please share your thoughts in the • Jenkins User Conference Mobile App. • Find the session in the app and click • on the feedback area.