SlideShare a Scribd company logo
Managing Jenkins with Python
Vijay Kumar B.<vijaykumar@bravegnu.org>
Continuous Integration
Every developer makes changes to the code and pushes them to the version control system.
The continuous integration server
pulls the code from repository
runs unit tests on the code and verifies its sanity.
Benefits
Accidentally missed out files are detected early.
Code is verified in a clean room environment.
Code can be tested in various target operating systems and configurations.
Build breakages and unit test breakages are immediately notified.
Continuous Integration Servers
Jenkins - popular continuous integration server written in Java.
Other open source continuous integration servers:
BuildBot
CruiseControl
Drone.io
GitLab CI
Setup @ Zilogic
Jenkins Jobs
A job specifies
where to checkout the source from
the commands to build the code
what to do with built artifacts.
Jobs are created through a web interface.
Fetching Source Code
Specify where to get the source from.
Specify whether to build periodically, or build when code is changed.
Build Steps and Post Build Actions
Specify what commands are to be executed to build and run unit tests.
Specify who should receive notifications, on build failure.
Job Representation
No text file representation that can be edited by hand.
Only a web interface to edit jobs.
Job representation is dumped to XML format, using persistence APIs.
config.xml
<project>
...
<scm class="hudson.scm.SubversionSCM" plugin="subversion@2.1">
<locations>
<hudson.scm.SubversionSCM_-ModuleLocation>
<remote>https://pike.zilogic.com/svn/proj/ansible-desktop
/trunk</remote>
...
</hudson.scm.SubversionSCM_-ModuleLocation>
</locations>
...
</scm>
...
<triggers>
<hudson.triggers.SCMTrigger>
<spec>H/15 * * * *</spec>
<ignorePostCommitHooks>false</ignorePostCommitHooks>
</hudson.triggers.SCMTrigger>
</triggers>
config.xml (Contd.)
...
<builders>
...
<hudson.tasks.Shell>
<command>export BUILD_VERSION=$BUILD_ID
make -f .jenkins.mk before_script
make -f .jenkins.mk script
</command>
</hudson.tasks.Shell>
...
</builders>
<publishers>
<hudson.tasks.Mailer plugin="mailer@1.10">
<recipients>vijaykumar</recipients>
...
</hudson.tasks.Mailer>
</publishers>
...
</project>
Problem
Managing Jenkins jobs through Web UI, does not scale.
Jobs are created by copying an existing job, and modifying it!
Violation of the DRY rule: Don’t Repeat Yourself!
Solution
Many people are trying to address the issue in various ways:
Job DSL plugin - https://github.com/jenkinsci/job-dsl-plugin/
Jenkins Job Builder - http://docs.openstack.org/infra/jenkins-job-builder/
Autojenkins - https://github.com/txels/autojenkins
Autojenkins
Jenkins provides REST API
Create jobs
Fetch config.xml of existing jobs
Update config.xml
Autojenkins
Python package that wraps over the REST API
Provides many useful funtions
Template Job
A template job can be created with place holders.
The job is disabled, which means Jenkins will not run it.
Autojenkins can create new jobs based on the template job, and values specified for the
placeholders
def create_copy(self, job, template, enable=True, _force=False,
**context):
"""
Create a job from a template job.
"""
Project DB
Description for each project for which CI is required.
name: ansible-desktop
template: python-template
summary: Ansible scripts for updating config. and installed
packages.
owner: vijaykumar
branches:
- 1.0
- 2.0
Used to populate the template, and create the jobs.
Per Project Build File
The chunk of what is different across projects in the build steps.
The build steps are put up in a Makefile called .build.mk within the project folder.
The template just invokes a make target in the .build.mk.
As a bonus, the CI build steps are under version control. This is similar to what Travis CI
does.
Script to Update Jobs
A class ProjInfo to hold the per project information.
name
summary
owner
template
branches
Script to Update Jobs (Contd.)
The following code creates a job for each project.
jenkins = Jenkins(self._config.jenkins_url,
auth=(self._username, self._password))
ci_jobname = "%s-ci" % self._proj_info.name
jenkins.create_copy(ci_jobname,
template_job=self._proj_info.template,
enable=True,
_force=True,
proj_summary=self._proj_info.summary,
proj_name=self._proj_info.name,
owner=self._proj_info.owner)
Finishing Notes
Job update script itself runs as a job under Jenkins!
Manage over 150 jobs at Zilogic.
Separate release and CI jobs, for each project.

More Related Content

PDF
The Job DSL Plugin: Introduction & What’s New
PPTX
Job DSL Plugin for Jenkins
PPTX
Configuration As Code: The Job DSL Plugin
PPTX
Jenkins Job DSL plugin
PDF
Rule jenkins with configuration as code
PPTX
Blazor - the successor of angular/react/vue?
PPTX
Continuous integration of_puppet_code
PDF
10+ Deploys Per Day: Dev and Ops Cooperation at Flickr
The Job DSL Plugin: Introduction & What’s New
Job DSL Plugin for Jenkins
Configuration As Code: The Job DSL Plugin
Jenkins Job DSL plugin
Rule jenkins with configuration as code
Blazor - the successor of angular/react/vue?
Continuous integration of_puppet_code
10+ Deploys Per Day: Dev and Ops Cooperation at Flickr

What's hot (20)

PDF
Gradle - From minutes to seconds: minimizing build times
PDF
Dynamic bpm design by doing lightning talk
PPTX
How we built a job board in one week with JHipster
PPTX
React native - React(ive) Way To Build Native Mobile Apps
PDF
Super Charged Configuration As Code
PPTX
React Native
PPTX
Blazor and Azure Functions - a serverless approach
PDF
Azure web functions little bites of services
PDF
Build your application in seconds and optimize workflow as much as you can us...
PDF
Developing, building, testing and deploying react native apps
PDF
JUC Europe 2015: Configuration as Code: The Job DSL Plugin
PPTX
MeteorJS Session
PDF
React.js - and how it changed our thinking about UI
PDF
Web Performance Part 4 "Client-side performance"
PPTX
Untangling - fall2017 - week 9
PDF
From zero to hero with React Native!
PDF
Practical continuous quality gates for development process
PPTX
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
PPT
Infrastructure Automation at Scale
PDF
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
Gradle - From minutes to seconds: minimizing build times
Dynamic bpm design by doing lightning talk
How we built a job board in one week with JHipster
React native - React(ive) Way To Build Native Mobile Apps
Super Charged Configuration As Code
React Native
Blazor and Azure Functions - a serverless approach
Azure web functions little bites of services
Build your application in seconds and optimize workflow as much as you can us...
Developing, building, testing and deploying react native apps
JUC Europe 2015: Configuration as Code: The Job DSL Plugin
MeteorJS Session
React.js - and how it changed our thinking about UI
Web Performance Part 4 "Client-side performance"
Untangling - fall2017 - week 9
From zero to hero with React Native!
Practical continuous quality gates for development process
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
Infrastructure Automation at Scale
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
Ad

Viewers also liked (19)

PDF
InsideSales Overview 2016
PDF
Forskningskommunikasjon: Mulig, meningsfullt og morsomt 27.08.2013
PDF
Kunsten å kommunisere kunnskap
PDF
New poster
PPTX
JetStor NAS 724UX and 724UX 10G ZFS appliance
PPTX
Arte egipcio
PDF
Forskningskommunikasjon i tradisjonelle og sosiale medier universitetet i sta...
PDF
Western new england university brochure 2
PDF
Regulamento açoriano
PDF
Outubro rosa 15.10
PPTX
Why School Should Use Linux
PDF
Rapid Fire Tools: Top Ways to Use IT Assessments to Win New Business & Grow
PPT
PPTX
Imagen Global
PDF
Inside Sales Strategies for MSPs
PPT
M1 PPT
PPT
Fotos de praias
PPT
Next-Generation Native Apps
PPT
HISTÒRIA DEL POP-ROCK (50s i 60s)
InsideSales Overview 2016
Forskningskommunikasjon: Mulig, meningsfullt og morsomt 27.08.2013
Kunsten å kommunisere kunnskap
New poster
JetStor NAS 724UX and 724UX 10G ZFS appliance
Arte egipcio
Forskningskommunikasjon i tradisjonelle og sosiale medier universitetet i sta...
Western new england university brochure 2
Regulamento açoriano
Outubro rosa 15.10
Why School Should Use Linux
Rapid Fire Tools: Top Ways to Use IT Assessments to Win New Business & Grow
Imagen Global
Inside Sales Strategies for MSPs
M1 PPT
Fotos de praias
Next-Generation Native Apps
HISTÒRIA DEL POP-ROCK (50s i 60s)
Ad

Similar to Managing Jenkins with Python (20)

PDF
Jenkins & IaC
PPTX
Pipeline as code - new feature in Jenkins 2
PDF
Jenkins CI
PDF
Continuous Integration using Jenkins with Python
PPTX
Continuous integration using jenkins
ODP
Jenkins Pipelining and Gatling Integration
PDF
Scaling Jenkins Devops presentation
PPTX
Jenkins presentation
PPT
Jenkins CI
PDF
413450-rc218-cdw-jenkins-workflow
PPTX
Eclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/Hudson
PPTX
Build Time Hacking
PDF
Gitlab and Lingvokot
PPTX
varun JENKINS.pptx
PPTX
Hudson
 
PDF
Priming Your Teams For Microservice Deployment to the Cloud
PPTX
DevOps-CI_CD_JAVA_JAVA______Jenkins.pptx
PPTX
PDF
Release with confidence
Jenkins & IaC
Pipeline as code - new feature in Jenkins 2
Jenkins CI
Continuous Integration using Jenkins with Python
Continuous integration using jenkins
Jenkins Pipelining and Gatling Integration
Scaling Jenkins Devops presentation
Jenkins presentation
Jenkins CI
413450-rc218-cdw-jenkins-workflow
Eclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/Hudson
Build Time Hacking
Gitlab and Lingvokot
varun JENKINS.pptx
Hudson
 
Priming Your Teams For Microservice Deployment to the Cloud
DevOps-CI_CD_JAVA_JAVA______Jenkins.pptx
Release with confidence

More from Vijay Kumar Bagavath Singh (7)

PDF
Automated Backporting of Linux Drivers
PDF
Memory Management in Python
PDF
Managing Desktops with Ansible
PDF
SlidesManaging Desktops with Ansible
PDF
Bitten By Python
PDF
Hangman: Design and Implementation
PDF
Breaking Free with Rope
Automated Backporting of Linux Drivers
Memory Management in Python
Managing Desktops with Ansible
SlidesManaging Desktops with Ansible
Bitten By Python
Hangman: Design and Implementation
Breaking Free with Rope

Managing Jenkins with Python

  • 1. Managing Jenkins with Python Vijay Kumar B.<vijaykumar@bravegnu.org>
  • 2. Continuous Integration Every developer makes changes to the code and pushes them to the version control system. The continuous integration server pulls the code from repository runs unit tests on the code and verifies its sanity. Benefits Accidentally missed out files are detected early. Code is verified in a clean room environment. Code can be tested in various target operating systems and configurations. Build breakages and unit test breakages are immediately notified.
  • 3. Continuous Integration Servers Jenkins - popular continuous integration server written in Java. Other open source continuous integration servers: BuildBot CruiseControl Drone.io GitLab CI
  • 5. Jenkins Jobs A job specifies where to checkout the source from the commands to build the code what to do with built artifacts. Jobs are created through a web interface.
  • 6. Fetching Source Code Specify where to get the source from. Specify whether to build periodically, or build when code is changed.
  • 7. Build Steps and Post Build Actions Specify what commands are to be executed to build and run unit tests. Specify who should receive notifications, on build failure.
  • 8. Job Representation No text file representation that can be edited by hand. Only a web interface to edit jobs. Job representation is dumped to XML format, using persistence APIs.
  • 10. config.xml (Contd.) ... <builders> ... <hudson.tasks.Shell> <command>export BUILD_VERSION=$BUILD_ID make -f .jenkins.mk before_script make -f .jenkins.mk script </command> </hudson.tasks.Shell> ... </builders> <publishers> <hudson.tasks.Mailer plugin="mailer@1.10"> <recipients>vijaykumar</recipients> ... </hudson.tasks.Mailer> </publishers> ... </project>
  • 11. Problem Managing Jenkins jobs through Web UI, does not scale. Jobs are created by copying an existing job, and modifying it! Violation of the DRY rule: Don’t Repeat Yourself!
  • 12. Solution Many people are trying to address the issue in various ways: Job DSL plugin - https://github.com/jenkinsci/job-dsl-plugin/ Jenkins Job Builder - http://docs.openstack.org/infra/jenkins-job-builder/ Autojenkins - https://github.com/txels/autojenkins
  • 13. Autojenkins Jenkins provides REST API Create jobs Fetch config.xml of existing jobs Update config.xml Autojenkins Python package that wraps over the REST API Provides many useful funtions
  • 14. Template Job A template job can be created with place holders. The job is disabled, which means Jenkins will not run it. Autojenkins can create new jobs based on the template job, and values specified for the placeholders def create_copy(self, job, template, enable=True, _force=False, **context): """ Create a job from a template job. """
  • 15. Project DB Description for each project for which CI is required. name: ansible-desktop template: python-template summary: Ansible scripts for updating config. and installed packages. owner: vijaykumar branches: - 1.0 - 2.0 Used to populate the template, and create the jobs.
  • 16. Per Project Build File The chunk of what is different across projects in the build steps. The build steps are put up in a Makefile called .build.mk within the project folder. The template just invokes a make target in the .build.mk. As a bonus, the CI build steps are under version control. This is similar to what Travis CI does.
  • 17. Script to Update Jobs A class ProjInfo to hold the per project information. name summary owner template branches
  • 18. Script to Update Jobs (Contd.) The following code creates a job for each project. jenkins = Jenkins(self._config.jenkins_url, auth=(self._username, self._password)) ci_jobname = "%s-ci" % self._proj_info.name jenkins.create_copy(ci_jobname, template_job=self._proj_info.template, enable=True, _force=True, proj_summary=self._proj_info.summary, proj_name=self._proj_info.name, owner=self._proj_info.owner)
  • 19. Finishing Notes Job update script itself runs as a job under Jenkins! Manage over 150 jobs at Zilogic. Separate release and CI jobs, for each project.