SlideShare a Scribd company logo
1 of 19
Download to read offline
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

What's hot

Gradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build timesGradle - From minutes to seconds: minimizing build times
Gradle - From minutes to seconds: minimizing build timesRene Gröschke
 
Dynamic bpm design by doing lightning talk
Dynamic bpm design by doing lightning talkDynamic bpm design by doing lightning talk
Dynamic bpm design by doing lightning talkITD Systems
 
How we built a job board in one week with JHipster
How we built a job board in one week with JHipsterHow we built a job board in one week with JHipster
How we built a job board in one week with JHipsterKile Niklawski
 
React native - React(ive) Way To Build Native Mobile Apps
React native - React(ive) Way To Build Native Mobile AppsReact native - React(ive) Way To Build Native Mobile Apps
React native - React(ive) Way To Build Native Mobile AppsJimit Shah
 
Super Charged Configuration As Code
Super Charged Configuration As CodeSuper Charged Configuration As Code
Super Charged Configuration As CodeAlan Beale
 
Blazor and Azure Functions - a serverless approach
Blazor and Azure Functions - a serverless approachBlazor and Azure Functions - a serverless approach
Blazor and Azure Functions - a serverless approachAlex Pshul
 
Azure web functions little bites of services
Azure web functions little bites of servicesAzure web functions little bites of services
Azure web functions little bites of servicesAaron Petry
 
Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...Build your application in seconds and optimize workflow as much as you can us...
Build your application in seconds and optimize workflow as much as you can us...Alex S
 
Developing, building, testing and deploying react native apps
Developing, building, testing and deploying react native appsDeveloping, building, testing and deploying react native apps
Developing, building, testing and deploying react native appsLeena N
 
JUC Europe 2015: Configuration as Code: The Job DSL Plugin
JUC Europe 2015: Configuration as Code: The Job DSL PluginJUC Europe 2015: Configuration as Code: The Job DSL Plugin
JUC Europe 2015: Configuration as Code: The Job DSL PluginCloudBees
 
React.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIReact.js - and how it changed our thinking about UI
React.js - and how it changed our thinking about UIMarcin Grzywaczewski
 
Web Performance Part 4 "Client-side performance"
Web Performance Part 4  "Client-side performance"Web Performance Part 4  "Client-side performance"
Web Performance Part 4 "Client-side performance"Binary Studio
 
Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Untangling - fall2017 - week 9
Untangling - fall2017 - week 9Derek Jacoby
 
From zero to hero with React Native!
From zero to hero with React Native!From zero to hero with React Native!
From zero to hero with React Native!Commit University
 
Practical continuous quality gates for development process
Practical continuous quality gates for development processPractical continuous quality gates for development process
Practical continuous quality gates for development processAndrii Soldatenko
 
LONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentationLONDON SDET MEETUP - Difference between Selenium and Cypress presentation
LONDON SDET MEETUP - Difference between Selenium and Cypress presentationSriram Angajala
 
Infrastructure Automation at Scale
Infrastructure Automation at ScaleInfrastructure Automation at Scale
Infrastructure Automation at ScaleDataCentred
 
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas VochtenO365Con18 - Working with PowerShell, VS Code and GitHub - Thomas Vochten
O365Con18 - Working with PowerShell, VS Code and GitHub - Thomas VochtenNCCOMMS
 

What's hot (20)

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

Viewers also liked

InsideSales Overview 2016
InsideSales Overview 2016InsideSales Overview 2016
InsideSales Overview 2016Dan Cone
 
Forskningskommunikasjon: Mulig, meningsfullt og morsomt 27.08.2013
Forskningskommunikasjon: Mulig, meningsfullt og morsomt 27.08.2013Forskningskommunikasjon: Mulig, meningsfullt og morsomt 27.08.2013
Forskningskommunikasjon: Mulig, meningsfullt og morsomt 27.08.2013Audun Farbrot
 
Kunsten å kommunisere kunnskap
Kunsten å kommunisere kunnskapKunsten å kommunisere kunnskap
Kunsten å kommunisere kunnskapAudun Farbrot
 
JetStor NAS 724UX and 724UX 10G ZFS appliance
JetStor NAS 724UX and 724UX 10G ZFS applianceJetStor NAS 724UX and 724UX 10G ZFS appliance
JetStor NAS 724UX and 724UX 10G ZFS applianceGene Leyzarovich
 
Arte egipcio
Arte egipcioArte egipcio
Arte egipcioRAPFITERO
 
Forskningskommunikasjon i tradisjonelle og sosiale medier universitetet i sta...
Forskningskommunikasjon i tradisjonelle og sosiale medier universitetet i sta...Forskningskommunikasjon i tradisjonelle og sosiale medier universitetet i sta...
Forskningskommunikasjon i tradisjonelle og sosiale medier universitetet i sta...Audun Farbrot
 
Western new england university brochure 2
Western new england university brochure 2Western new england university brochure 2
Western new england university brochure 2Abhishek Bajaj
 
Why School Should Use Linux
Why School Should Use LinuxWhy School Should Use Linux
Why School Should Use LinuxMohammedSharafi
 
Rapid Fire Tools: Top Ways to Use IT Assessments to Win New Business & Grow
Rapid Fire Tools: Top Ways to Use IT Assessments to Win New Business & GrowRapid Fire Tools: Top Ways to Use IT Assessments to Win New Business & Grow
Rapid Fire Tools: Top Ways to Use IT Assessments to Win New Business & GrowMAXfocus
 
Inside Sales Strategies for MSPs
Inside Sales Strategies for MSPsInside Sales Strategies for MSPs
Inside Sales Strategies for MSPsSolarwinds N-able
 
Next-Generation Native Apps
Next-Generation Native AppsNext-Generation Native Apps
Next-Generation Native Appsdreamforce2006
 
HISTÒRIA DEL POP-ROCK (50s i 60s)
HISTÒRIA DEL POP-ROCK (50s i 60s)HISTÒRIA DEL POP-ROCK (50s i 60s)
HISTÒRIA DEL POP-ROCK (50s i 60s)musicaarce
 

Viewers also liked (19)

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

Similar to Managing Jenkins with Python

Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2Michal Ziarnik
 
Continuous Integration using Jenkins with Python
Continuous Integration using Jenkins with PythonContinuous Integration using Jenkins with Python
Continuous Integration using Jenkins with PythonInexture Solutions
 
Continuous integration using jenkins
Continuous integration using jenkinsContinuous integration using jenkins
Continuous integration using jenkinsVinay H G
 
Jenkins Pipelining and Gatling Integration
Jenkins Pipelining and  Gatling IntegrationJenkins Pipelining and  Gatling Integration
Jenkins Pipelining and Gatling IntegrationKnoldus Inc.
 
Scaling Jenkins Devops presentation
Scaling Jenkins Devops presentationScaling Jenkins Devops presentation
Scaling Jenkins Devops presentationprajdesh26
 
413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflowAndy Pemberton
 
Announcing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck TalksAnnouncing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck TalksAmazon Web Services
 
Eclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/Hudson
Eclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/HudsonEclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/Hudson
Eclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/HudsonVladLica
 
Gitlab and Lingvokot
Gitlab and LingvokotGitlab and Lingvokot
Gitlab and LingvokotLingvokot
 
varun JENKINS.pptx
varun JENKINS.pptxvarun JENKINS.pptx
varun JENKINS.pptxVgPolampalli
 
Hudson
HudsonHudson
Hudson8x8
 
Priming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the CloudPriming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the CloudMatt Callanan
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidenceJohn Congdon
 

Similar to Managing Jenkins with Python (20)

Jenkins & IaC
Jenkins & IaCJenkins & IaC
Jenkins & IaC
 
Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2Pipeline as code - new feature in Jenkins 2
Pipeline as code - new feature in Jenkins 2
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
Continuous Integration using Jenkins with Python
Continuous Integration using Jenkins with PythonContinuous Integration using Jenkins with Python
Continuous Integration using Jenkins with Python
 
Continuous integration using jenkins
Continuous integration using jenkinsContinuous integration using jenkins
Continuous integration using jenkins
 
Jenkins Pipelining and Gatling Integration
Jenkins Pipelining and  Gatling IntegrationJenkins Pipelining and  Gatling Integration
Jenkins Pipelining and Gatling Integration
 
Scaling Jenkins Devops presentation
Scaling Jenkins Devops presentationScaling Jenkins Devops presentation
Scaling Jenkins Devops presentation
 
Jenkins presentation
Jenkins presentationJenkins presentation
Jenkins presentation
 
Jenkins CI
Jenkins CIJenkins CI
Jenkins CI
 
413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow413450-rc218-cdw-jenkins-workflow
413450-rc218-cdw-jenkins-workflow
 
Announcing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck TalksAnnouncing AWS CodeBuild - January 2017 Online Teck Talks
Announcing AWS CodeBuild - January 2017 Online Teck Talks
 
Eclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/Hudson
Eclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/HudsonEclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/Hudson
Eclipse DemoCamp Bucharest 2014 - Continuous Integration Jenkins/Hudson
 
Build Time Hacking
Build Time HackingBuild Time Hacking
Build Time Hacking
 
Gitlab and Lingvokot
Gitlab and LingvokotGitlab and Lingvokot
Gitlab and Lingvokot
 
varun JENKINS.pptx
varun JENKINS.pptxvarun JENKINS.pptx
varun JENKINS.pptx
 
Hudson
HudsonHudson
Hudson
 
CI
CICI
CI
 
Priming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the CloudPriming Your Teams For Microservice Deployment to the Cloud
Priming Your Teams For Microservice Deployment to the Cloud
 
Jenkins
JenkinsJenkins
Jenkins
 
Release with confidence
Release with confidenceRelease with confidence
Release with confidence
 

More from Vijay Kumar Bagavath Singh (7)

Automated Backporting of Linux Drivers
Automated Backporting of Linux DriversAutomated Backporting of Linux Drivers
Automated Backporting of Linux Drivers
 
Memory Management in Python
Memory Management in PythonMemory Management in Python
Memory Management in Python
 
Managing Desktops with Ansible
Managing Desktops with AnsibleManaging Desktops with Ansible
Managing Desktops with Ansible
 
SlidesManaging Desktops with Ansible
SlidesManaging Desktops with AnsibleSlidesManaging Desktops with Ansible
SlidesManaging Desktops with Ansible
 
Bitten By Python
Bitten By PythonBitten By Python
Bitten By Python
 
Hangman: Design and Implementation
Hangman: Design and ImplementationHangman: Design and Implementation
Hangman: Design and Implementation
 
Breaking Free with Rope
Breaking Free with Rope Breaking Free with Rope
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.