Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
DevOps for Web Development
DevOps for Web Development

DevOps for Web Development: Achieve the Continuous Integration and Continuous Delivery of your web applications with ease

eBook
$9.99 $43.99
Paperback
$54.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

DevOps for Web Development

Chapter 2. Continuous Integration with Jenkins 2

"The way to get started is to quit talking and begin doing."                                                                       -Walt Disney

Jenkins 2 has arrived. It comes with built-in support for delivery pipelines, improved usability, a new setup experience, and complete backward compatibility with existing Jenkins installations. We will be using Jenkins 2 in this book.

This chapter describes in detail how Jenkins plays an important role in continuous integration. It covers how to prepare a runtime environment for application lifecycle management and configure it with Jenkins...

Introduction

We all know what Continuous Integration (CI) is, right? It is the first step in our journey.

 

"The journey of a thousand miles begins with one step."

 
 -- Lao Tzu, the father of Taoism

In simple words, CI is a software engineering practice where each check-in made by a developer is verified by either of the following:

  • Pull mechanism: Executing an automated build at a scheduled time
  • Push mechanism: Executing an automated build when changes are saved in the repository

This step is followed by executing a unit test against the latest changes available in the source code repository.

Jenkins doesn't need the introduction; it is an open source and one the most popular CI tools available in the market. It helps in automating the repetitive task of CI. Jenkins makes the process effective and transparent.

 

"We are what we repeatedly do. Excellence, then, is not an act, but a habit."

 
 -- Aristotle

The next question you may ask is what...

Installing Jenkins

Jenkins provides us with multiple ways to install it for all types of users. We can install it on at least the following operating systems:

  • Ubuntu/Debian
  • Windows
  • Mac OS X
  • OpenBSD
  • FreeBSD
  • openSUSE
  • Gentoo
  • CentOS/Fedora/Red Hat

One of the easiest options I recommend is to use a WAR file. A WAR file can be used with or without a container or web application server. Having Java is a must before we try to use a WAR file for Jenkins, which can be done as follows:

  1. Download the jenkins.war file from https://jenkins.io/ .
  2. Open command prompt in Windows or a terminal in Linux, go to the directory where the jenkins.war file is stored, and execute the following command:

    java - jar jenkins.war
    

  3. Once Jenkins is fully up and running, as shown in the following screenshot, explore it in the web browser by visiting http://localhost:8080.:

    Installing Jenkins

  4. By default, Jenkins works on port 8080. Execute the following command from the command-line:

    java -jar jenkins.war --httpPort=9999
    

  5. For HTTPS, use the following...

The Jenkins dashboard

The Jenkins dashboard is a simple and powerful place where we can manage all builds and therefore manage the application delivery pipeline as well. Open http://<localhost or IP address>:8080 from browser. Log in with the user credentials which we created earlier. It will direct us to the dashboard.

Let's understand the dashboard parameters:

  • New Item: It is used to create a new build job, pipeline, or build flow in Jenkins 2:

The Jenkins dashboard

  • Manage Jenkins: It allows a Jenkins 2 administrator to manage plugins, users, security, nodes, credentials, global tool configuration, and so on:

The Jenkins dashboard

  • To know about the existing nodes used for build execution, click on Manage Nodes. The master node entry will be available. It is the node where Jenkins is installed. We can add multiple slave nodes to distribute the load, which we will learn later in this chapter:

The Jenkins dashboard

Now that we have installed Jenkins and become familiar with the Jenkins dashboard, the next step is to configure different tools...

Configuring Java and Maven in Jenkins

In Jenkins 2, the Global Tool Configuration section has been introduced, which is a good move. All major configurations related to external tools, their locations, and automatic installer tools can be made in this section. Earlier, these configurations were part of Configure System, which used to make that page bit cluttered.

Configuring Java

To configure Java, provide a Name and the JAVA_HOME path, or check Install automatically checkbox:

Configuring Java

Configuring Maven

To configure Maven, download the Maven installer from https://maven.apache.org/download.cgi , and extract it to the directory on your Jenkins virtual machine. In the Global Tool Configuration section, provide the Name and MAVEN_HOME path, or check Install automatically checkbox:

Configuring Maven

That's it! Our major configuration for running a simple build is done. Now, let's go to the home page of the Jenkins dashboard to create and configure a build job.

Introduction


We all know what Continuous Integration (CI) is, right? It is the first step in our journey.

 

"The journey of a thousand miles begins with one step."

 
 -- Lao Tzu, the father of Taoism

In simple words, CI is a software engineering practice where each check-in made by a developer is verified by either of the following:

  • Pull mechanism: Executing an automated build at a scheduled time

  • Push mechanism: Executing an automated build when changes are saved in the repository

This step is followed by executing a unit test against the latest changes available in the source code repository.

Jenkins doesn't need the introduction; it is an open source and one the most popular CI tools available in the market. It helps in automating the repetitive task of CI. Jenkins makes the process effective and transparent.

 

"We are what we repeatedly do. Excellence, then, is not an act, but a habit."

 
 -- Aristotle

The next question you may ask is what makes Jenkins so popular. I already gave you one reason...

Installing Jenkins


Jenkins provides us with multiple ways to install it for all types of users. We can install it on at least the following operating systems:

  • Ubuntu/Debian

  • Windows

  • Mac OS X

  • OpenBSD

  • FreeBSD

  • openSUSE

  • Gentoo

  • CentOS/Fedora/Red Hat

One of the easiest options I recommend is to use a WAR file. A WAR file can be used with or without a container or web application server. Having Java is a must before we try to use a WAR file for Jenkins, which can be done as follows:

  1. Download the jenkins.war file from https://jenkins.io/ .

  2. Open command prompt in Windows or a terminal in Linux, go to the directory where the jenkins.war file is stored, and execute the following command:

    java - jar jenkins.war
    

  3. Once Jenkins is fully up and running, as shown in the following screenshot, explore it in the web browser by visiting http://localhost:8080.:

  4. By default, Jenkins works on port 8080. Execute the following command from the command-line:

    java -jar jenkins.war --httpPort=9999
    

  5. For HTTPS, use the following...

The Jenkins dashboard


The Jenkins dashboard is a simple and powerful place where we can manage all builds and therefore manage the application delivery pipeline as well. Open http://<localhost or IP address>:8080 from browser. Log in with the user credentials which we created earlier. It will direct us to the dashboard.

Let's understand the dashboard parameters:

  • New Item: It is used to create a new build job, pipeline, or build flow in Jenkins 2:

  • Manage Jenkins: It allows a Jenkins 2 administrator to manage plugins, users, security, nodes, credentials, global tool configuration, and so on:

  • To know about the existing nodes used for build execution, click on Manage Nodes. The master node entry will be available. It is the node where Jenkins is installed. We can add multiple slave nodes to distribute the load, which we will learn later in this chapter:

Now that we have installed Jenkins and become familiar with the Jenkins dashboard, the next step is to configure different tools that...

Configuring Java and Maven in Jenkins


In Jenkins 2, the Global Tool Configuration section has been introduced, which is a good move. All major configurations related to external tools, their locations, and automatic installer tools can be made in this section. Earlier, these configurations were part of Configure System, which used to make that page bit cluttered.

Configuring Java

To configure Java, provide a Name and the JAVA_HOME path, or check Install automatically checkbox:

Configuring Maven

To configure Maven, download the Maven installer from https://maven.apache.org/download.cgi , and extract it to the directory on your Jenkins virtual machine. In the Global Tool Configuration section, provide the Name and MAVEN_HOME path, or check Install automatically checkbox:

That's it! Our major configuration for running a simple build is done. Now, let's go to the home page of the Jenkins dashboard to create and configure a build job.

Creating and configuring a build job for a Java application with Maven


Jenkins builds configured with Maven understands how Maven works and what is required in terms of execution. It uses pom.xml to set up and create package files from the source files.

Now, let's perform steps to create and configure a new build job. Go to the Jenkins dashboard and click on New Item.

Go through all the available options of the types of jobs we can create. In our case, let's create a freestyle project for a demo:

  1. Enter an item name, such as PetClinic, then select Freestyle project. Now click on OK to continue:

  2. Let's verify what this operation does. Go to the Jenkins home directory, and navigate to the jobs directory. We can see that the directory has been created for the newly created job with the same name, as shown in the following screenshot:

Configuring and authenticating source code on GitHub


The next step is to configure a source code repository with the build job. We will use the open source Spring application hosted on GitHub, as explained in the previous chapter:

  1. After that, we will get a URL similar to https://github.com/mitesh51/spring-petclinic .

  2. Create a GitHub account and fork repository from https://github.com/spring-projects/spring-petclinic .

    Tip

    Install Git on a virtual machine using the instructions available in the documentation: Getting Started - Installing Git ( https://git-scm.com/book/en/v2/Getting-Started-Installing-Git ). To download a Windows application navigate to https://git-scm.com/ and click on Downloads for Windows.

  3. Let's generate a new SSH key to use for authentication. Open a terminal on a CentOS virtual machine with Git installed.

  4. Run ssh-keygen -t rsa -b 4096 -C "your_email@example.com", substituting your GitHub e-mail address.

  5. Press Enter when you are prompted with Enter file in which to save the...

Configuring build job


Now that Git authentication is done with, let's configure a PetClinic build job:

  1. Click on the PetClinic build job on the Jenkins dashboard. Then, click on the Configure link. You'll see the following page as shown here:

  2. Under Source Code Management, provide the GitHub URL for the sample Spring project we forked earlier, as shown in the following screenshot:

  3. We will configure Build Triggers and the Build Environment as shown here:

  4. Under Build, click on Add build step and select Invoke top-level Maven targets. Select the Maven Version we configured in Global Tools Configuration. Enter the Maven target and click on Save:

  5. Let's manually trigger the build by clicking on Build Now. After the build is complete, you'll see this:

  6. Click on the build number, the one with the #  symbol. Open Console Output. Verify the Git operations executing before Maven target execution:

  7. Once source code is available in the build job's workspace, the Maven target will be executed and the...

Configuring JUnit


Our sample application has JUnit test cases, and to execute them, we need to configure JUnit-related settings in the build job configuration:

  1. Under Post-build Actions, select Publish JUnit test result report.

  2. Provide a path for Test report XMLs based on the workspace.

  3. Click on Apply and then click on Save:

  4. After you've configured the JUnit settings for the build, wait for a scheduled build execution, or click on Build Now.

  5. Verify the build status on the Jenkins dashboard and you will see the Test Result link with a small summary. Click on Test Result:

  6. Verify all test execution statuses package wise. The page also provides information related to duration and failed test cases:

In the next section, we will cover the Dashboard View plugin, which helps us customize the view for build jobs.

The Dashboard View plugin - overview and usage


Dashboard View plugin provides a different view implementation, based on a portal kind of layout. We can select different build jobs to be included in a new view and configure different portlets for the view.

To configure it, follow these steps:

  1. Go to Plugin Manager from Manage Jenkins, and click on the Available tab. Search for the Dashboard View plugin and click on Install without restart:

  2. Once the plugin has been installed successfully, we can create a new view by clicking on the + sign on the Jenkins dashboard.

  3. Enter a View name, select the view type, and click on OK:

  4. Click on Edit and configure Dashboard Portlets for the top, left column, right column, and bottom. We can use different portlets, such as Test Statistics Chart, and Trends:

  5. Add different portlets based on your requirements into the view, and save it. Here's a sample view:

  6. After we run the build job, we can find a test result chart on the build job's dashboard as well:

Now...

Managing nodes


Jenkins provides a master-slave concept for managing the aforementioned scenarios. We can assign different build jobs to different slaves in the build configuration and use the master-slave system to manage its overall lifecycle. The master node itself can execute the build if a slave node is not configured explicitly in the build job configuration.

There are quite a few reasons for using this feature:

  • Build jobs require resources, and they compete for resource availability

  • A different runtime environment is required for different build jobs

  • It distributes the load across slave nodes

To make things clearer, we need not install Jenkins on the slave nodes. We only need to configure the slave nodes properly, which we will now cover.

The only requirements are the following:

  • The configurations and runtime environment have to be available on the slave node

  • The path needs to be configured correctly on the master node for the runtime environments or tools used by the slave node for execution...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Overcome the challenges of implementing DevOps for web applications, familiarize yourself with diverse third-party modules, and learn how to integrate them with bespoke code to efficiently complete tasks
  • Understand how to deploy web applications for a variety of Cloud platforms such as Amazon EC2, AWS Elastic Beanstalk, Microsoft Azure, Azure Web Apps, and Docker Container
  • Understand how to monitor applications deployed in Amazon EC2, AWS Elastic Beanstalk, Microsoft Azure, Azure Web Apps using Nagios, New Relic, Microsoft Azure, and AWS default monitoring features

Description

The DevOps culture is growing at a massive rate, as many organizations are adopting it. However, implementing it for web applications is one of the biggest challenges experienced by many developers and admins, which this book will help you overcome using various tools, such as Chef, Docker, and Jenkins. On the basis of the functionality of these tools, the book is divided into three parts. The first part shows you how to use Jenkins 2.0 for Continuous Integration of a sample JEE application. The second part explains the Chef configuration management tool, and provides an overview of Docker containers, resource provisioning in cloud environments using Chef, and Configuration Management in a cloud environment. The third part explores Continuous Delivery and Continuous Deployment in AWS, Microsoft Azure, and Docker, all using Jenkins 2.0. This book combines the skills of both web application deployment and system configuration as each chapter contains one or more practical hands-on projects. You will be exposed to real-world project scenarios that are progressively presented from easy to complex solutions. We will teach you concepts such as hosting web applications, configuring a runtime environment, monitoring and hosting on various cloud platforms, and managing them. This book will show you how to essentially host and manage web applications along with Continuous Integration, Cloud Computing, Configuration Management, Continuous Monitoring, Continuous Delivery, and Deployment.

Who is this book for?

If you are a system admin or application and web application developer with a basic knowledge of programming and want to get hands-on with tools such as Jenkins 2 and Chef, and Cloud platforms such as AWS and Microsoft Azure, Docker, New Relic, Nagios, and their modules to host, deploy, monitor, and manage their web applications, then this book is for you.

What you will learn

  • Grasp Continuous Integration for a JEE application—create and configure a build job for a Java application with Maven and with Jenkins 2.0
  • Create built-in delivery pipelines of Jenkins 2 and build a pipeline configuration for end-to-end automation to manage the lifecycle of Continuous Integration
  • Get to know all about configuration management using Chef to create a runtime environment
  • Perform instance provisioning in AWS and Microsoft Azure and manage virtual machines on different cloud platforms—install Knife plugins for Amazon EC2 and Microsoft Azure
  • Deploy an application in Amazon EC2, AWS Elastic Beanstalk, Microsoft Azure Web Apps, and a Docker container
  • Monitor infrastructure, application servers, web servers, and applications with the use of open source monitoring solutions and New Relic
  • Orchestrate multiple build jobs to achieve application deployment automation—create parameterized build jobs for end-to-end automation

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 24, 2016
Length: 408 pages
Edition : 1st
Language : English
ISBN-13 : 9781786468352
Languages :
Concepts :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Oct 24, 2016
Length: 408 pages
Edition : 1st
Language : English
ISBN-13 : 9781786468352
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 188.97
Learning DevOps: Continuously Deliver Better Software
$84.99
DevOps for Web Development
$54.99
Practical DevOps
$48.99
Total $ 188.97 Stars icon
Banner background image

Table of Contents

9 Chapters
1. Getting Started – DevOps Concepts, Tools, and Technologies Chevron down icon Chevron up icon
2. Continuous Integration with Jenkins 2 Chevron down icon Chevron up icon
3. Building the Code and Configuring the Build Pipeline Chevron down icon Chevron up icon
4. Installing and Configuring Chef Chevron down icon Chevron up icon
5. Installing and Configuring Docker Chevron down icon Chevron up icon
6. Cloud Provisioning and Configuration Management with Chef Chevron down icon Chevron up icon
7. Deploying Application in AWS, Azure, and Docker Chevron down icon Chevron up icon
8. Monitoring Infrastructure and Applications Chevron down icon Chevron up icon
9. Orchestrating Application Deployment Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(20 Ratings)
5 star 75%
4 star 15%
3 star 0%
2 star 0%
1 star 10%
Filter icon Filter
Top Reviews

Filter reviews by




Apoorva Shetty May 02, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Amazing book.. covers almost all concepts with added screenshots for clarity!Was a delight learning DevOps with the help of this book. Great work!
Amazon Verified review Amazon
MITESH H SHAH May 05, 2017
Full star icon Full star icon Full star icon Full star icon Full star icon 5
amazing book. Its wonderful to get knowledge abt DevOps in such easy and practical terms... Thank u so much
Amazon Verified review Amazon
Amazon Customer Jun 15, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Excellent book. Most of the dev ops topics are covered.
Amazon Verified review Amazon
Resident01 Jun 07, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This is a fantastic book for learning how to use all of the common dev ops tools. It's very well written and doesn't go too fast or too slow for uptake. The first chapter pretty much rushes you into the basics of what you'll be covering and then begins detailed explanations and setup steps to make it work. Me and DevOps generally don't get along and this book has been great.
Amazon Verified review Amazon
Ramarao Feb 06, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
It's good for Devops beginner.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.