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
Mex$179.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781786465702
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Oct 24, 2016
Length: 408 pages
Edition : 1st
Language : English
ISBN-13 : 9781786465702
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 Mex$85 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 Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 3,877.97
Learning DevOps: Continuously Deliver Better Software
Mex$1743.99
DevOps for Web Development
Mex$1128.99
Practical DevOps
Mex$1004.99
Total Mex$ 3,877.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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.