Jenkins is an open source automation server written in Java. Jenkins helps to automate the non-human part of software development process, with continuous integration and facilitating technical aspects of continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat.
3. Continuous Integration
• As defined by Martin Fowler
• In software engineering CI implements continuous process of applying quality control – small
pieces of effort applied frequently.
• It aims to improve the quality of software and to reduce time taken to deliver.
• This is done by replacing the traditional practice of applying quality control after completing
development with continuous integration.
4. What is CI?
• What it is
A development Methodology.
A daily developer integration.
Automated builds.
8. Jenkins
• Written in java
• Runs inside servlet container.
• Primarily written and developed by kosuke kawaguchi.
• Split from Hudson.
• Easy to install.
• Over 600+ Plugins.
• Can be scripted.
16. Jenkins plugins
Default Plugin Description
ANT Use to run talk from build.xml
Credentials To store Credentials in Jenkins
JavaDoc Publishes Javadoc
Junit Publishes junit test results
Mailer Supports Mail Sending
Subversion Supports SVN
Maven Integration Integration Jenkins with maven.
LDAP LDAP Authentication support
18. Plugin Tabs
Updates – Shows updates to already installed plugins.
Available – Shows plugins that are available for installation.
Installed – Shows plugins installed that have no problem.
Advanced – Allows manual upload of plugins
19. Pinning of Plugins
• Plugins that are bundled or preinstalled with Jenkins can be pinned.
• When Jenkins are updated all the plugins preinstalled are also
updated.
• But if any bundled plugin is manually updated it gets pinned to
current version of Jenkins.
• Update of Jenkins will not update this plugin.
• /Plugins/plugin_name.jpi.pinned is created.
• You can Unpin which means you are allowing the updates to happen.
20. Global Tools
• Manage Jenkins -> Global Tool Configuration
• Configure tools, their locations and automatic installers.
21. Automatic Install
• Install automatically allows you to have custom installers or scripts.
• Default is “Install from Apache” .
• Else you can extract an already downloaded file.
22. Maven Plugin
• In addition to other env variable maven plugin makes below variables available to your jobs or
scripts.
• This plugin exposes variables found from the project's POM (as of version 2.1):
• POM_DISPLAYNAME
• POM_VERSION
• POM_GROUPID
• POM_ARTIFACTID
• POM_PACKAGING
23. Javadoc Plugin
• Publishes your Javadoc if created by your build.
• Maven Projects
• Goal to run Javadoc:Javadoc
• Freestyle Projects
• Under “Add post-build action” -> Publish Javadoc
24. HTML Publisher
• Use to generate HTML files during the build.
• You can publish PMD Reports, Java Docs etc.
25. Git HUB
• It allows you to connect Git Hub with Jenkins.
• Trigger a build whenever push to repository happens.
26. Git Hub Tokens
• Goto Git Hub , log in, go to settings, personal access tokens , click on
Generate new token.
• Check repo:status
• Click on Generate Token and copy it.
• In Jenkins Management - > Configure System, Add a new GITHUB
server config.
• API URL: https://api.github.com
• Check Manage Hooks Check box.
• Click Add Button next to Credentials.
• Enter Credentials in the dialog box( Screen 2)
29. Automatic Build when code is pushed
• You will then have to tick the box indicated below – “Build when a change is pushed to GitHub”
30. Contd.
• Manage Jenkins -> Manage Plugins -> Available -> GitHub plugin
• Copy the url in « Override Hook URL. And uncheck specify another hook url for GitHub Configurations.
31. Contd.
• The GitHub steps are pretty straight forward. Open the “Webhooks
& Services” tab -> choose “Configure Services” -> find the Jenkins
(GitHub plugin option) and fill it in with a similar URL to the
following:
• http://<Name of Jenkins server>:8080/github-webhook/
32. Add WebHooks in Git Hub
• The GitHub steps are pretty straight forward. Open the “Webhooks & Services” tab -> choose “Configure
Services” -> find the Jenkins (GitHub plugin option) and fill it in with a similar URL to the following:
• http://<Name of Jenkins server>:8080/github-webhook/
33. Parameterised Builds
• Allows user to provide parameters for Build in a URL.
• Users are prompted to enter parameters before triggering build.
• Exposes $Jenkins/job/$job/parambuild URL to trigger build with
parameter.
34. Credential Plugin
• Provides convenient way to organize credentials across domains and
maintains password secret once.
• Used by other plugins indirectly when you are required to provide
credentials.
• There are multiple credentials plugin including.
• Plain credentials
• SSH Credentials
• Google Oath
• Dockers Common
35. Credential Plugin
• Kinds of Credentials
• Username with password
• SSH Username with private key
• Certificate.
• Scope of Credentials
• Global- Available to the object on which credentials is associated and all
objects that are children on that object.
• System – Only available to object on which credentials is associated.
Eg email
36. Jenkins Copy Artifact
• Allows you to copy artifacts built from other jobs into current workspace.
• Select the option from Build Steps.
37. Jenkins Copy Artifact (Contd)
• Files matched by the "Artifacts to copy" field are copied to the same directory structure as the
source build had You can use the "Flatten directories" option if you want the file(s) to be copied
to the root of the build workspace.
• Projects must enable “permission to copy Artifact” and select the project which is authorized to
copy artifacts.
38. • The location from which the artifacts are copied from is relative to:
• - the artifacts folder,
• - for the selected build,
• - for the job you selected to copy from
• So, first things first, you have to make sure that the job that you are copying from is actually
archiving the artifacts. It will not copy files from workspace (there are other plugins for that).
• To archive your artifacts, in the job the creates them, select post-build action "Archive the
artifacts", then provide a list of artifacts you want to archive, relative to workspace. For example,
to archive all zip files, regardless of where they are, use:
**/*.zip
• Or if you know that all your artifacts are inside the "build" folder, but there may be intermediate
directories in between, use:
build/**/*.zip
• Or simply provide a full path:
build/myartifactsfolder/myfile.zip
Jenkins Copy Artifact (Contd)
39. Jenkins Copy Artifact (Contd)
• Now, to view the artifacts available, navigate in your browser to the URL of the job from which
you want to copy, select the build you wish to copy from, and then append /artifact/ at the end,
or just click "Build Artifacts" link on the page:
example: http://localhost/job/YourJob/lastBuild/artifact/
• This will show a directory structure and all available artifacts. You can reference this in the "Copy
Artifacts" post-build step directly. Or you can use wildcards. For example, if you want to ignore
any directory structure, and just copy all *.zip files, your "Artifacts to copy" field should be:
**/*.zip
• The double stars ignore directories in between. You can use comma to separate multiple entries.
Alternatively, if you leave this field blank, it will copy all available artifacts.
• On the receiving end, the "Target directory" is relative to the Workspace of the job that is calling
the "Copy Artifacts" step.
• Lastly, if you don't care about the directory structure, check mark the "Flatten directories" option,
so that all artifacts end up in the same place, ignoring any folders in between.
40. Triggers
• Manual Build
• Click manually build now.
• On Schedule
• Use UNIX Cron rotation
• Minutes
• Hours
• Day of month
• Month
• Day of week
• When code changes in SCM
• Polling SCM
• Triggered on other builds.
42. Cron Format
• Jenkins uses UNIX Cron notation
• Minutes (0-59)
• * represents every value ***** means once every minute.
• / allows you to skip e.g. */5 means every 5 minute.
• Hours (0-23)
• Commas represents list of values e.g. 2,3 means at 2 and 3 am in morning.
• Day of month (1-31)
• Month (1-12)
• Day of week (0-7)
• Ranges are allowed 1-5 means between Monday to Friday.
1. By setting the schedule period to 15 13 * * * you tell jenkins to schedule the build every day of every month of every year at the 15th
minute of the 13th hour of the day.
2. If you want to schedule your build every 5 minutes, this will do the job : */5 * * * *
3. If you want to schedule your build every day at 8h00, this will do the job : 0 8 * * *
43. Cron (Contd)
• Jenkins lets you set up multiple times, separated by line breaks.
• If you need it to build daily at 7am, along with every Sunday at 4pm, the below works well
• H 7 * * *
• H 16 * * 0
44. Types of JOB
• Maven
• Free Style
• Monitor an External Job
• Multi Configurations jobs
46. Maven vs FreeStyle
• A maven project is a project that will analyze the pom.xml file in greater detail and
produce a project that's geared towards the targets that are invoked. The maven project
is smart enough to incorporate build targets like the javadoc or test targets and
automatically setup the reports for those targets. There is little configuration required for
it. See: http://wiki.hudson-ci.org/display/HUDSON/Building+a+maven2+project for more
information on Maven project.
• A Free-Style project is a project that can incorporate almost any type of build. While a
maven project you can only build maven projects, the Free-Style project is the more
"generic" form of a project. You can execute shell/dos scripts, invoke ant, and a lot more.
Majority of the plugins are written to use the free-style project. The maven module is
limited in that it can't invoke a shell script, or anything else just the maven targets. See:
http://wiki.hudson-ci.org/display/HUDSON/Building+a+software+project for more
information on a Free-Style project.
52. Email / IRC integration
Follow the steps as illustrated in previous slides
Go to localhost:8080 (default port for Jenkins)
Navigate to Manage Jenkins Configure System
Tick , Use SMTP Authentication
Follow the details as per screenshot
Give the username and password
Tick, Use SSL
Enter SMTP port
Reply to address
Charset
Please enter a recipient email address
Test by clicking on Test configuration
53. Email Functionality
• Default Email notification in Jenkins Post Build Action.
• Email address can be separated by commas.
54. Email (Contd)
• Use Email Template management plugin if you don’t want use default
one.
61. Health report amplification factor
• The amplification factor to apply to test failures when computing the test result contribution to
the build health score.
• The default factor is 1.0
• A factor of 0.0 will disable the test result contribution to build health score.
• A factor of 0.1 means that 10% of tests failing will score 99% health
• A factor of 0.5 means that 10% of tests failing will score 95% health
• A factor of 1.0 means that 10% of tests failing will score 90% health
• A factor of 2.0 means that 10% of tests failing will score 80% health
• A factor of 2.5 means that 10% of tests failing will score 75% health
• A factor of 5.0 means that 10% of tests failing will score 50% health
• A factor of 10.0 means that 10% of tests failing will score 0% health
71. Configure Pom.xml
• To know how to configure pom.xml to set up code coverage tools.
• Refer pom.xml of this project:
https://github.com/Viyaan/JenkinsJobFlow
72. HTML Validation
• Install Unicorn Validator
• In Build step select unicorn validator.
• Enter the URL of site to validate.
76. Backup Manager plugin parameters
• Backup directory: A shared folder where back up is dumped.
• Format: At what format it is dumped.
• Verbose: Backup will be logged.
• If you want to schedule your back periodically use thinBackup plugin.
Editor's Notes
Tools can be either configured to be installed automatically or the path of the preinstalled tools can be specified.