Learning Continuous Integration with Jenkins - Second Edition

Book description

Speed up the software delivery process and software productivity using the latest features of Jenkins

About This Book

  • Take advantage of a Continuous Integration and Continuous Delivery solution to speed up productivity and achieve faster software delivery
  • See all the new features introduced in Jenkins 2.x, such as Pipeline as code, Multibranch pipeline, Docker Plugin, and more
  • Learn to implement Continuous Integration and Continuous Delivery by orchestrating multiple DevOps tools using Jenkins

Who This Book Is For

The book is for those with little or no previous experience with Agile or CI and CD. It's a good starting point for anyone new to this field who wants to leverage the benefits of CI and CD to increase productivity and reduce delivery time. It's ideal for Build and Release engineers, DevOps engineers, SCM (Software Configuration Management) engineers, developers, testers, and project managers. If you're already using Jenkins for CI, you can take your project to the next level—CD.

What You Will Learn

  • Get to know some of the most popular ways to set up Jenkins
  • See all the new features introduced in the latest Jenkins, such as pipeline as code, Multibranch pipeline, and more
  • Manage users, projects, and permissions in Jenkins to ensure better security
  • Leverage the power of plugins in Jenkins
  • Learn how to create a CI pipeline using Jenkins Blue Ocean
  • Create a distributed build farm using Docker and use it with Jenkins
  • Implement CI and CD using Jenkins
  • See the difference between CD and Continuous Deployment
  • Understand the concepts of CI

In Detail

In past few years, agile software development has seen tremendous growth. There is a huge demand for software delivery solutions that are fast yet flexible to numerous amendments. As a result, Continuous Integration (CI) and Continuous Delivery (CD) methodologies are gaining popularity.

This book starts off by explaining the concepts of CI and its significance in the Agile. Next, you'll learn how to configure and set up Jenkins in many different ways. The book exploits the concept of "pipeline as code" and various other features introduced in the Jenkins 2.x release to their full potential. We also talk in detail about the new Jenkins Blue Ocean interface and the features that help to quickly and easily create a CI pipeline. Then we dive into the various features offered by Jenkins one by one, exploiting them for CI and CD. Jenkins' core functionality and flexibility allows it to fit in a variety of environments and can help streamline the development process for all stakeholders. Next, you'll be introduced to CD and will learn how to achieve it using Jenkins.

Through this book's wealth of best practices and real-world tips, you'll discover how easy it is to implement CI and CD using Jenkins.

Style and approach

The book uses a simple Maven project to demonstrate the implementation of CI and CD using Jenkins. This step-by-step guide shows you how to implement CI/CD and can be used as a template to perform CI/CD in your projects.

Table of contents

  1. Title Page
    1. Second Edition
  2. Copyright
    1. Learning Continuous Integration with Jenkins
      1. Second Edition
  3. Credits
  4. About the Author
  5. About the Reviewer
  6. www.PacktPub.com
    1. Why subscribe?
  7. Customer Feedback
  8. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Conventions
    5. Reader feedback
    6. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  9. Concepts of Continuous Integration
    1. Software Development Life Cycle
      1. Requirement analysis
      2. Design
      3. Implementation
      4. Testing
      5. Evolution
    2. Waterfall model of software development
      1. Disadvantages of the Waterfall model
      2. Advantages of the Waterfall model
    3. Agile to the rescue
      1. The twelve agile principles
      2. How does the Agile software development process work?
      3. Advantages of Agile software development process
    4. The Scrum framework
      1. Important terms used in the Scrum framework
      2. How does Scrum work?
        1. Sprint Planning
        2. Sprint cycle
        3. Daily Scrum meeting
        4. Monitoring Sprint progress
        5. Sprint Review
        6. Sprint Retrospective
    5. Continuous Integration
      1. Agile runs on CI
      2. Types of projects that benefit from CI
    6. Elements of CI
      1. Version control system
      2. Branching strategy
        1. GitFlow branching model
      3. CI tool
      4. Self-triggered builds
      5. Code coverage
        1. Code coverage tools
      6. Static code analysis
      7. Automated testing
      8. Binary repository tools
      9. Automated packaging
    7. Benefits of using CI
      1. Freedom from long integrations
      2. Metrics
      3. Catching issues faster
      4. Rapid development
        1. Spend more time adding features
    8. Summary
  10. Installing Jenkins
    1. Running Jenkins inside a servlet container
      1. Prerequisites
      2. Installing Java
      3. Installing Apache Tomcat
      4. Enabling the firewall and port 8080
      5. Configuring the Apache Tomcat server
      6. Installing Jenkins on the Apache Tomcat server
      7. Installing Jenkins alone on an Apache Tomcat server
      8. Setting up the Jenkins home path
    2. Installing a standalone Jenkins server on Windows
      1. Prerequisites
      2. Installing Java
      3. Installing the latest stable version of Jenkins
      4. Starting, stopping, and restarting Jenkins on Windows
    3. Installing a standalone Jenkins server on Ubuntu
      1. Prerequisites
      2. Installing Java
      3. Installing the latest version of Jenkins
      4. Installing the latest stable version of Jenkins
      5. Starting, stopping, and restarting Jenkins on Ubuntu
    4. Installing a standalone Jenkins server on Red Hat Linux
      1. Prerequisites
      2. Installing Java
      3. Installing the latest version of Jenkins
      4. Installing the latest stable version of Jenkins
      5. Starting, stopping, and restarting Jenkins on Red Hat Linux
    5. Running Jenkins behind a reverse proxy
      1. Prerequisites
      2. Installing and configuring Nginx
      3. Configuring the firewall on a Nginx server
      4. Starting, stopping, and restarting the Nginx server
      5. Securing Nginx using OpenSSL
        1. Creating an SSL certificate
        2. Creating strong encryption settings
        3. Modifying the Nginx configuration
        4. Enabling the changes and testing our Nginx setup
      6. Configuring the Jenkins server
      7. Adding reverse proxy settings to the Nginx configuration
      8. Running Nginx and Jenkins on the same machine
    6. Running Jenkins on Docker
      1. Prerequisites
      2. Setting up a Docker host
        1. Setting up the repository
        2. Installing Docker
        3. Installing from a package
      3. Running the Jenkins container
      4. Running a Jenkins container using a data volume
        1. Testing the data volume
    7. Creating development and staging instances of Jenkins
      1. Prerequisites
      2. Creating an empty data volume
      3. Copying data between data volumes
      4. Creating the development and staging instances
    8. Summary
  11. The New Jenkins
    1. The Jenkins setup wizard
      1. Prerequisites
      2. Unlocking Jenkins
      3. Customizing Jenkins
      4. Creating the first admin user
    2. The new Jenkins pipeline job
      1. Prerequisite
      2. Creating a Jenkins pipeline job
      3. The Global Tool Configuration page
      4. Jenkins pipeline Stage View
    3. Declarative Pipeline syntax
      1. Basic structure of a Declarative Pipeline
        1. The node block
        2. The stage block
        3. Directives
        4. Steps
    4. Jenkins pipeline syntax utility
      1. Prerequisite
        1. Installing the Pipeline Maven Integration Plugin
        2. Creating a Jenkins pipeline using the pipeline syntax utility
    5. Multibranch pipeline
      1. Prerequisite
        1. Adding GitHub credentials inside Jenkins
        2. Configuring Webhooks on GitHub from Jenkins
        3. Create a new repository on GitHub
        4. Using a Jenkinsfile
      2. Creating a Multibranch pipeline in Jenkins
      3. Re-register the Webhooks
      4. Jenkins Multibranch pipeline in action
        1. Creating a new feature branch to test the multibranch pipeline
    6. Jenkins Blue Ocean
      1. Installing the Jenkins Blue Ocean plugin
      2. View your regular Jenkins pipeline in Blue Ocean
      3. Creating a pipeline in Blue Ocean
    7. Summary
  12. Configuring Jenkins
    1. The Jenkins Plugin Manager
      1. Updating Jenkins plugins
      2. Installing a new Jenkins plugin
      3. Uninstalling or downgrading a Jenkins plugin
      4. Configuring proxy settings in Jenkins
      5. Manually installing a Jenkins plugin
    2. Jenkins backup and restore
      1. Installing the Periodic Backup plugin
      2. Configuring the Periodic Backup plugin
      3. Creating a Jenkins backup
      4. Restoring a Jenkins backup
      5. Viewing the backup and restore logs
    3. Upgrading Jenkins
      1. Upgrading Jenkins running on Tomcat Server
      2. Upgrading standalone Jenkins running on Windows
      3. Upgrading standalone Jenkins running on Ubuntu
      4. Upgrading Jenkins running on a Docker container
    4. User administration
      1. Enabling/disabling global security on Jenkins
      2. Enabling/disabling computers to remember user credentials
      3. Authentication methods
        1. Delegating to a servlet container
        2. Jenkins' own user database
        3. LDAP
        4. Unix user/group database
      4. Creating new users inside Jenkins
      5. People page
        1. User information and settings in Jenkins
      6. Authorization methods
        1. Anyone can do anything
        2. Legacy mode
        3. Logged-in users can do anything
        4. Matrix-based security
        5. Project-based Matrix Authorization Strategy
    5. Summary
  13. Distributed Builds
    1. Distributed build and test
    2. The Jenkins Manage Nodes page
    3. Adding Jenkins slaves – standalone Linux machine/VMs
      1. Passing environment variables to Jenkins slaves
      2. Passing tools' locations to Jenkins slaves
      3. Launching a Jenkins slave via SSH
    4. More about the active Jenkins slave
    5. Adding Jenkins slaves – standalone Windows machine/VMs
      1. Launching a Jenkins slave via Java Web Start
    6. Adding Jenkins slaves – Docker containers
      1. Prerequisites
        1. Setting up a Docker server
          1. Setting up the repository
          2. Installing Docker using apt-get
          3. Installing Docker using a .deb package
      2. Enabling Docker remote API
        1. Modifying the docker.conf file
        2. Modifying the docker.service file
      3. Installing the Docker plugin
      4. Configuring the Docker plugin
      5. Creating a Docker image – Jenkins slave
      6. Adding Docker container credentials in Jenkins
      7. Updating the Docker settings inside Jenkins
    7. Summary
  14. Installing SonarQube and Artifactory
    1. Installing and configuring SonarQube
      1. Installing Java
      2. Downloading the SonarQube package
      3. Running the SonarQube application
      4. Resetting the default credentials and generating a token
      5. Creating a project inside SonarQube
      6. Installing the build breaker plugin for SonarQube
      7. Creating quality gates
      8. Updating the default quality profile
      9. Installing the SonarQube plugin in Jenkins
      10. Configuring the SonarQube plugin in Jenkins
    2. Installing and configuring Artifactory
      1. Installing Java
      2. Downloading the Artifactory package
      3. Running the Artifactory application
      4. Resetting the default credentials and generating an API key
      5. Creating a repository in Artifactory
      6. Adding Artifactory credentials inside Jenkins
      7. Installing the Artifactory plugin in Jenkins
      8. Configuring the Artifactory Plugin
    3. Summary
  15. Continuous Integration Using Jenkins
    1. Jenkins CI design  
      1. Branching strategy
        1. The master branch
        2. The integration branch
        3. The feature branch
      2. The CI pipeline
      3. Toolset for CI
    2. Creating the CI pipeline
      1. Creating a new repository on GitHub
      2. Using the SonarQube scanner for Maven
      3. Writing the Jenkinsfile for CI
        1. Spawning a Docker container – build agent
        2. Downloading the latest source code from VCS
        3. Pipeline code to perform the build and unit test
        4. Pipeline code to perform static code analysis
        5. Pipeline code to perform integration testing
        6. Pipeline code to publish built artifacts to Artifactory
        7. Combined CI pipeline code
      4. Using a Jenkinsfile
      5. Creating a Multibranch Pipeline in Jenkins
      6. Re-registering the Webhooks
    3. Continuous Integration in action
      1. Viewing static code analysis in SonarQube
      2. Accessing SonarQube analysis right from Jenkins
      3. Viewing artifacts in Artifactory
      4. Failing the build when quality gate criteria are not met
    4. Summary
  16. Continuous Delivery Using Jenkins
    1. Jenkins CD design
      1. Branching strategy
        1. The release branch
      2. CD pipeline
      3. Toolset for CD
    2. Creating a Docker image – performance testing
      1. Adding Docker container credentials in Jenkins
      2. Updating the Docker settings inside Jenkins
    3. Creating a performance test using JMeter
      1. Installing Java
      2. Installing Apache JMeter
      3. Starting JMeter
      4. Creating a performance test case
        1. Creating a thread group
        2. Creating a sampler
        3. Adding a listener
    4. The CD pipeline
      1. Writing the Jenkinsfile for CD
        1. Revisiting the pipeline code for CI
        2. Pipeline code to stash the build artifacts
        3. Spawning a Docker container – performance testing
        4. Pipeline code to start Apache Tomcat
        5. Pipeline code to deploy build artifacts
        6. Pipeline code to run performance testing
        7. Pipeline code to promote build artifacts in Artifactory
        8. Combined CD pipeline code
    5. CD in action
    6. Summary
  17. Continuous Deployment Using Jenkins
    1. What is Continuous Deployment?
      1. How Continuous Deployment is different from Continuous Delivery
      2. Who needs Continuous Deployment?
    2. Creating a production server
      1. Installing Vagrant
      2. Installing VirtualBox
      3. Creating a VM using Vagrant
        1. Creating a Vagrantfile
        2. Spawning a VM using Vagrant
        3. Adding production server credentials inside Jenkins
    3. Installing a Jenkins slave on a production server
    4. Creating a Jenkins Continuous Deployment pipeline
      1. A revisit to the pipeline code for CD
      2. Pipeline code for a production Jenkins slave
      3. Pipeline code to download binaries from Artifactory
      4. Combined Continuous Deployment pipeline code
      5. Update the Jenkinsfile
    5. Continuous Delivery in action
    6. Summary
  18. Supporting Tools and Installation Guide
    1. Exposing your localhost server to the internet
    2. Installing Git on Windows/Linux 
      1. Installing Git on Windows
      2. Installing Git on Linux

Product information

  • Title: Learning Continuous Integration with Jenkins - Second Edition
  • Author(s): Nikhil Pathania
  • Release date: December 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781788479356