Jenkins is an open source automation server (after Jenkins 2.0 was released) written in Java. It was one of the most popular Continuous Integration (CI) tools used to build and test different kinds of projects. Now, it is also used for Continuous Delivery (CD) after Jenkins 2.0. This chapter describes in detail the basics of CI and overview of Jenkins 2. It describes the importance of CI and CD as a practice to cultivate DevOps culture in recent times.
This chapter also describes installation and configuration of Jenkins 2. We are going to take a jumpstart tour through some of the key features of Jenkins and plugin installations as well.
To be precise, we will discuss the following topics in this chapter:
- Introduction of Jenkins 2 and its features
- Installation of Jenkins 2
- Jumpstart tour of Jenkins dashboard
- Configuration settings in Jenkins
- Overview of CICD pipeline
Lets get started! On your marks, get set, go!
In this chapter, we will see what Jenkins 2 is and the new features introduced regarding CI as a part of our DevOps journey. We will cover the following steps to complete our DevOps journey. Each chapter is a stepping stone to reach the next one. It is always good to have an incremental approach so we can measure our success and feel the pain points as well to realize the value of this journey:
At the end of this chapter, we will know essential things about Jenkins 2 and how it is a game changer in terms of CD. It is no longer a CI server. It is on its way to becoming a mature product in the category of automation servers by focusing on Continuous Delivery after Jenkins 2.0 is released.
Let's first understand what CI is. CI is one of the most popular application development practices in recent times. Developers integrate bug fixes, new feature development, or innovative functionality in a code repository. The CI tool verifies the integration process with an automated build and test to detect issues with current sources of an application and provide quick feedback:
Jenkins is a simple, extensible, and user friendly open source tool that provides continuous integration services for application development. Jenkins supports SCM tools such as Git, Subversion, Star Team, and CVS, AccuRev. Jenkins can build Apache Ant and Apache Maven-based projects.
The concept of plugins makes Jenkins more attractive, easy to learn, and easy to use. There are various categories of plugins available, such as the following:
- Source code management
- Slave launchers and controllers
- Build triggers
- Build tools
- Build notifiers
- Build reports
- Other post-build actions
- External site/tool integrations
- UI plugins
- Authentication and user management
- Android development
- iOS development
- .NET development
- Ruby development
- Library plugins
Jenkins defines interfaces or abstract classes that model a facet of a build system. Interfaces or abstract classes agree on what needs to be implemented, and Jenkins uses plugins to extend those implementations.
With Jenkins 2, the focus is also on CD where the application is deployed in the specific environment using an automated approach. Jenkins 2 is a clear signal regarding the focus on both CI and CD best practices of DevOps culture and not on CI only.
Jenkins is one of the most popular automation servers in the market, and the reasons for its popularity are some of the following features:
- Easy installation on different operating systems, Arch Linux, FreeBSD, Gentoo, MacOS X, openBSD, openSUSE, RedHAT/Fedora/CentOS, Ubuntu/Debian, Windows, and it is also available for Docker and as generic Java packages too.
- Easy upgrades: Jenkins has very speedy release cycles (long-term support and weekly releases).
- Simple and easy to use user interface in Jenkins 2.x -.
- Set of suggested plugins at the time of installation.
- Improved new item page.
- Improved job configuration page with easy navigation.
- Jenkins 2 supports pipelines as code that uses domain-specific language (DSL) to model application delivery pipelines as code; we can utilize the pipelines as code and keep them in a repository and maintain versions in a similar way to source code.
- Easily extensible with the use of third-party plugins: there are over 400 plugins.
- Easy to configure the setup environment in the user interface. It is also possible to customize user interface as you wish.
- Master slave architecture supports distributed builds to reduce the load on CI servers.
- Build scheduling based on cron expressions.
- Shell and Windows command execution that makes any command-line tool integration in the pipeline very easy.
- Notification support related to build status.
Let's start with Jenkins 2.x installation. Go to https://jenkins.io/ and click on the
Download button to download packages for installation of Jenkins:
At https://jenkins.io/download/, we get two sections. One is for
Long-term Support (LTS) that is selected after every 12 weeks from regular releases as the stable release from that duration.
Another section is
Weekly release, which has bug fixes and is made available to users and developers.
We will use the
Generic Java Package (.war) file in our installation of Jenkins as shown in the following screenshot.
The reason for selecting the
.war file for the Jenkins installation is its ease of use across operating systems. Jenkins is written in Java, and in any case, to execute Jenkins we need the latest Java version installed on our system. For Jenkins Installation, Java 8 is recommended. It is recommended to have 1-GB of memory.
Verify the Java installation by using the
java -version command in the command prompt or terminal based on the operating system.
Generic Java Package (.war) from https://jenkins.io/download/ on the local system as follows:
Before we start Jenkins, we will set the
JENKINS_HOME environment variable. When we install and configure Jenkins, all the files reside in the
jenkins directory by default. We often need to change the default location for our convenience. We can do that by setting the
JENKINS_HOME environment variable. Follow the following steps:
- To set the
JENKINS_HOMEenvironment variable in Windows 10, go to
All Control Panel Items | Systemand click on
Advanced system settings|
Environment Variables...Please see the manual for other operating systems to set
- Click on
New. Enter the variable name and location and click
- Now our
JENKINS_HOMEis set so Jenkins will use that directory to store all configuration files.
- Open the command prompt or terminal (depending on your operating system) and execute the following command:
Java -jar Jenkins.war
- This is a fresh installation of Jenkins, so initial setup is required. Note the password:
- Once Jenkins is fully up and running, visit
http://localhost:8080and it will open the
Getting Startedpage to
Unlock Jenkins. Give the password we copied from the terminal or go to the location given in the dialog box. Copy the password from there and click on
- Click on
Installto see the suggested plugins. If we are behind the proxy, then another dialog box will pop up before this page to provide proxy details:
- Wait while all the plugins are installed properly:
- Verify the green tick boxes for all the plugins that have been installed successfully:
- Once all plugins are installed successfully, create the first admin user and click on
Save and Finish:
- Click on
Start using Jenkins:
In the next section, we will see details of the Jenkins dashboard.
The Jenkins dashboard is the place where all the operations related to CI and CD can be managed:
Click on the
Manage Jenkins link on the Jenkins dashboard. Here, we can configure
Users, and more:
Manage Plugins. You will see the following tabs:
Updatestab provides details on updates available on the installed plugins.
Availabletab provides a list of plugins that are not installed yet.
Installedtab provides a list of plugins that are already installed.
Advancedtab contains sections to configure proxies so we can download plugins even after we are behind the proxy. It also provides sections to upload HPI files for plugins in case we have already downloaded the plugin from the internet:
Manage Jenkins section, click on
By default, the system on which Jenkins is installed is a master node. This is the section that can be utilized to create the master agent architecture that we will cover later in the book:
In the next section, we will cover different kinds of configuration available in the
Manage Jenkins section.
Manage Jenkins, click on the
Configure System link.
Here, we can get information about the
JENKINS_HOME directory, the workspace root directory, and so on. We can set the Jenkins URL as well in this section:
Manage Jenkins, click on
Configure Global Security to see the security settings available in Jenkins. We will cover role-based access, matrix-based project security, and other features in later parts of this book:
Manage Jenkins, click on the
Global Tool Configuration link to provide details related to all tools available on the system that can be utilized to perform certain tasks. Depending on plugins related to specific tools, that section will appear on this page.
Another important thing to mention is that we can configure multiple versions of the same tool. For example, we can configure Java 6, Java 7, and Java 8. It is highly likely that different projects require different versions of Java for their execution. In such cases, we can configure multiple JDKs here and utilize specific JDKs in specific build jobs:
As discussed earlier in this chapter, the
Manage Plugins section has an
Advanced tab that allows us to configure proxy details.
This was all about the basic installation and configuration of Jenkins 2.x, and now we will cover what we are going to achieve in this book.
The application development life cycle is traditionally a lengthy manual process. In addition, it requires effective collaboration between development and operations teams. The CI/CD pipeline is a demonstration of automation involved in the application development lifecycle that contains automated build execution, automated test execution, notifications to stakeholders, and deployment in different runtime environments. Effectively, a deployment pipeline is a combination of continuous integration and continuous delivery, and hence a part of DevOps practices. The following figure depicts the pipeline process. Depending on the culture of organization and the available tools, the flow and tools may differ:
Members of the development team check code into a source code repository. Continuous integration products such as Jenkins are configured to poll changes from the code repository. Changes in the repository are downloaded to the local workspace and Jenkins triggers a build process that is assisted by Ant or Maven or Gradle or any build script. Automated test execution, unit testing, static code analysis, reporting, and notification of successful or failed build processes are also parts of the Continuous Integration process.
Once the build is successful, it can be deployed to different runtime environments such as testing, pre-production, production, and so on. Deploying a WAR file in terms of a JEE application is normally the final stage in the deployment pipeline. However, after the deployment of this package into a pre-production environment, functional and security testing can be performed.
One of the biggest benefits of the pipeline is a faster feedback cycle. Identification of issues in the application in early stages and no dependency on manual effort make this entire end-to-end process more effective.
In the following chapters, we will see how Jenkins can be used to implement CI and CD practices in modernizing the culture of an organization.
Congratulations! We have reached the end of this chapter. So far, we have covered the basics of CI and have introduced Jenkins and its features. We have also completed the installation of Jenkins using generic package files. We also completed a quick tour of features available in the Jenkins dashboard. In addition to this, we have discussed the CI/CD pipeline and its importance in cultivating DevOps culture.
Now that we are able to use our automation server, Jenkins, we can begin creating a job and verify how Jenkins works. Before that, we will see how different configurations can be done in Jenkins in the next chapter.