You are previewing Learning Continuous Integration with Jenkins.
O'Reilly logo
Learning Continuous Integration with Jenkins

Book Description

A beginner's guide to implementing Continuous Integration and Continuous Delivery using Jenkins

About This Book

  • Speed up and increase software productivity and software delivery using Jenkins

  • Automate your build, integration, release, and deployment processes with Jenkins—and learn how continuous integration (CI) can save you time and money

  • Explore the power of continuous delivery using Jenkins through powerful real-life examples

  • Who This Book Is For

    This book is for anyone who wants to exploit the power of Jenkins. This book servers a great starting point for those who are in the field DevOps and would like to leverage the benefits of CI and continuous delivery in order to increase productivity and reduce delivery time.

    What You Will Learn

  • Take advantage of a continuous delivery solution to achieve faster software delivery

  • Speed up productivity using a continuous Integration solution through Jenkins

  • Understand the concepts of CI and continuous delivery

  • Orchestrate many DevOps tools using Jenkins to automate builds, releases, deployment, and testing

  • Explore the various features of Jenkins that make DevOps activities a piece of cake

  • Configure multiple build machines in Jenkins to maintain load balancing

  • Manage users, projects, and permissions in Jenkins to ensure better security

  • Leverage the power of plugins in Jenkins

  • In Detail

    In past few years, Agile software development has seen tremendous growth across the world. There is huge demand for software delivery solutions that are fast yet flexible to frequent amendments. As a result, CI and continuous delivery methodologies are gaining popularity. Jenkins’ core functionality and flexibility allows it to fit in a variety of environments and can help streamline the development process for all stakeholders.

    This book starts off by explaining the concepts of CI and its significance in the Agile world with a whole chapter dedicated to it. Next, you’ll learn to configure and set up Jenkins. You’ll gain a foothold in implementing CI and continuous delivery methods. We dive into the various features offered by Jenkins one by one exploiting them for CI.

    After that, you’ll find out how to use the built-in pipeline feature of Jenkins. You’ll see how to integrate Jenkins with code analysis tools and test automation tools in order to achieve continuous delivery. Next, you’ll be introduced to continuous deployment and learn 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 a CI service with Jenkins.

    Style and approach

    This is a step-by-step guide to setting up a CI and continuous delivery system loaded with hands-on examples

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

    Table of Contents

    1. Learning Continuous Integration with Jenkins
      1. Table of Contents
      2. Learning Continuous Integration with Jenkins
      3. Credits
      4. About the Author
      5. About the Reviewer
      6. www.PacktPub.com
        1. eBooks, discount offers, and more
          1. Why subscribe?
      7. 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. Errata
          3. Piracy
          4. Questions
      8. 1. Concepts of Continuous Integration
        1. The agile software development process
          1. Software development life cycle
            1. Requirement analysis
            2. Design
            3. Implementation
            4. Testing
            5. Evolution
          2. The waterfall model of software development
            1. Disadvantages of the waterfall model
            2. Who needs the waterfall model?
          3. Agile to the rescue
            1. How does the agile software development process work?
          4. The Scrum framework
            1. Important terms used in the Scrum framework
          5. How does Scrum work?
            1. Sprint planning
            2. Sprint cycle
            3. Daily scrum meeting
            4. Monitoring sprint progress
            5. The sprint review
            6. Sprint retrospective
        2. Continuous Integration
          1. An example to understand Continuous Integration
          2. Agile runs on Continuous Integration
          3. Types of project that benefit from Continuous Integration
        3. The best practices of Continuous Integration
          1. Developers should work in their private workspace
          2. Rebase frequently from the mainline
          3. Check-in frequently
          4. Frequent build
          5. Automate the testing as much as possible
          6. Don't check-in when the build is broken
          7. Automate the deployment
          8. Have a labeling strategy for releases
          9. Instant notifications
        4. How to achieve Continuous Integration
          1. Development operations
          2. Use a version control system
            1. An example to understand VCS
            2. Types of version control system
              1. Centralized version control systems
              2. Distributed version control systems
          3. Use repository tools
          4. Use a Continuous Integration tool
          5. Creating a self-triggered build
          6. Automate the packaging
          7. Using build tools
            1. Maven
            2. MSBuild
          8. Automating the deployments
          9. Automating the testing
          10. Use static code analysis
          11. Automate using scripting languages
            1. Perl
          12. Test in a production-like environment
          13. Backward traceability
          14. Using a defect tracking tool
        5. Continuous Integration benefits
          1. Freedom from long integrations
          2. Production-ready features
          3. Analyzing and reporting
          4. Catch issues faster
          5. Spend more time adding features
          6. Rapid development
        6. Summary
      9. 2. Setting up Jenkins
        1. Introduction to Jenkins
          1. What is Jenkins made of?
            1. Jenkins job
              1. Jenkins parameters
              2. Jenkins build
              3. Jenkins post-build actions
            2. Jenkins pipeline
            3. Jenkins plugins
          2. Why use Jenkins as a Continuous Integration server?
            1. It's open source
            2. Community-based support
            3. Lots of plugins
            4. Jenkins has a cloud support
          3. Jenkins as a centralized Continuous Integration server
          4. Hardware requirements
        2. Running Jenkins inside a container
          1. Installing Jenkins as a service on the Apache Tomcat server
            1. Prerequisites
            2. Installing Jenkins along with other services on the Apache Tomcat server
            3. Installing Jenkins alone on the Apache Tomcat server
          2. Setting up the Jenkins home path
            1. Method 1 – configuring the context.xml file
            2. Method 2 – creating the JENKINS_HOME environment variable
          3. Why run Jenkins inside a container?
            1. Conclusion
        3. Running Jenkins as a standalone application
          1. Setting up Jenkins on Windows
            1. Installing Jenkins using the native Windows package
            2. Installing Jenkins using the jenkins.war file
            3. Changing the port where Jenkins runs
          2. Setting up Jenkins on Ubuntu
            1. Installing the latest version of Jenkins
            2. Installing the latest stable version of Jenkins
            3. Changing the Jenkins port on Ubuntu
          3. Setting up Jenkins on Fedora
            1. Installing the latest version of Jenkins
            2. Installing the latest stable version of Jenkins
            3. Changing the Jenkins port on Fedora
        4. Sample use cases
          1. Netflix
          2. Yahoo!
        5. Summary
      10. 3. Configuring Jenkins
        1. Creating your first Jenkins job
          1. Adding a build step
          2. Adding post-build actions
          3. Configuring the Jenkins SMTP server
          4. Running a Jenkins job
          5. Jenkins build log
          6. Jenkins home directory
        2. Jenkins backup and restore
          1. Creating a Jenkins job to take periodic backup
          2. Restoring a Jenkins backup
        3. Upgrading Jenkins
          1. Upgrading Jenkins running on the Tomcat server
          2. Upgrading standalone Jenkins master on Windows
          3. Upgrading standalone Jenkins master running on Ubuntu
            1. Upgrading to the latest version of Jenkins
            2. Upgrading to the latest stable version of Jenkins
            3. Upgrading Jenkins to a specific stable version
          4. Script to upgrade Jenkins on Windows
          5. Script to upgrade Jenkins on Ubuntu
        4. Managing Jenkins plugins
          1. The Jenkins Plugins Manager
          2. Installing a Jenkins plugin to take periodic backup
          3. Configuring the periodic backup plugin
        5. User administration
          1. Enabling global security on Jenkins
          2. Creating users in Jenkins
            1. Creating an admin user
            2. Creating other users
          3. Using the Project-based Matrix Authorization Strategy
        6. Summary
      11. 4. Continuous Integration Using Jenkins – Part I
        1. Jenkins Continuous Integration Design
          1. The branching strategy
            1. Master branch
            2. Integration branch
            3. Feature branch
          2. The Continuous Integration pipeline
            1. Jenkins pipeline to poll the feature branch
              1. Jenkins job 1
              2. Jenkins job 2
            2. Jenkins pipeline to poll the integration branch
              1. Jenkins job 1
              2. Jenkins job 2
          3. Toolset for Continuous Integration
        2. Setting up a version control system
          1. Installing Git
          2. Installing SourceTree (a Git client)
          3. Creating a repository inside Git
            1. Using SourceTree
            2. Using the Git commands
          4. Uploading code to Git repository
            1. Using SourceTree
            2. Using the Git commands
          5. Configuring branches in Git
            1. Using SourceTree
            2. Using the Git commands
          6. Git cheat sheet
        3. Configuring Jenkins
          1. Installing the Git plugin
          2. Installing and configuring JDK
            1. Setting the Java environment variables
            2. Configuring JDK inside Jenkins
          3. Installing and configuring Maven
            1. Installing Maven
            2. Setting the Maven environment variables
            3. Configuring Maven inside Jenkins
          4. Installing the e-mail extension plugin
        4. The Jenkins pipeline to poll the feature branch
          1. Creating a Jenkins job to poll, build, and unit test code on the feature1 branch
            1. Polling version control system using Jenkins
            2. Compiling and unit testing the code on the feature branch
            3. Publishing unit test results
            4. Publishing Javadoc
            5. Configuring advanced e-mail notification
          2. Creating a Jenkins job to merge code to the integration branch
            1. Using the build trigger option to connect two or more Jenkins jobs
          3. Creating a Jenkins job to poll, build, and unit test code on the feature2 branch
          4. Creating a Jenkins job to merge code to the integration branch
        5. Summary
      12. 5. Continuous Integration Using Jenkins – Part II
        1. Installing SonarQube to check code quality
          1. Setting the Sonar environment variables
          2. Running the SonarQube application
          3. Creating a project inside SonarQube
          4. Installing the build breaker plugin for Sonar
          5. Creating quality gates
          6. Installing SonarQube Scanner
          7. Setting the Sonar Runner environment variables
        2. Installing Artifactory
          1. Setting the Artifactory environment variables
          2. Running the Artifactory application
          3. Creating a repository inside Artifactory
        3. Jenkins configuration
          1. Installing the delivery pipeline plugin
          2. Installing the SonarQube plugin
          3. Installing the Artifactory plugin
        4. The Jenkins pipeline to poll the integration branch
          1. Creating a Jenkins job to poll, build, perform static code analysis, and integration tests
            1. Polling the version control system for changes using Jenkins
            2. Creating a build step to perform static analysis
            3. Creating a build step to build and integration test code
            4. Configuring advanced e-mail notifications
          2. Creating a Jenkins job to upload code to Artifactory
            1. Configuring the Jenkins job to upload code to Artifactory
        5. Creating a nice visual flow for the Continuous Integration pipeline
        6. Continuous Integration in action
          1. Configuring Eclipse to connect with Git
          2. Adding a runtime server to Eclipse
          3. Making changes to the Feature1 branch
          4. Committing and pushing changes to the Feature1 branch
          5. Real-time Jenkins pipeline to poll the Feature1 branch
            1. The Jenkins job to poll, build, and unit test code on the Feature1 branch
            2. The Jenkins job to merge code to integration branch
          6. Real-time Jenkins pipeline to poll the integration branch
            1. The Jenkins job to poll, build, perform static code analysis, and perform integration tests
            2. The Jenkins job to upload code to Artifactory
        7. Summary
      13. 6. Continuous Delivery Using Jenkins
        1. What is Continuous Delivery?
        2. Continuous Delivery Design
          1. Continuous Delivery pipeline
            1. Pipeline to poll the feature branch
              1. Jenkins job 1
              2. Jenkins job 2
            2. Pipeline to poll the integration branch
              1. Jenkins job 1
              2. Jenkins job 2
              3. Jenkins job 3
              4. Jenkins job 4
              5. Jenkins job 5
          2. Toolset for Continuous Delivery
        3. Configuring our testing server
          1. Installing Java on the testing server
          2. Installing Apache JMeter for performance testing
          3. Creating a performance test case
          4. Installing the Apache Tomcat server on the testing server
        4. Jenkins configuration
          1. Configuring the performance plugin
          2. Configuring the TestNG plugin
          3. Changing the Jenkins/Artifactory/Sonar web URLs
          4. Modifying the Maven configuration
          5. Modifying the Java configuration
          6. Modifying the Git configuration
          7. Configuring Jenkins slaves on the testing server
        5. Creating Jenkins Continuous Delivery pipeline
          1. Modifying the existing Jenkins job
            1. Modifying the advanced project
            2. Modifying the Jenkins job that performs the Integration test and static code analysis
            3. Modifying the Jenkins job that uploads the package to Artifactory
          2. Creating a Jenkins job to deploy code on the testing server
          3. Creating a Jenkins job to run UAT
          4. Creating a Jenkins job to run the performance test
        6. Creating a nice visual flow for the Continuous Delivery pipeline
        7. Creating a simple user acceptance test using Selenium and TestNG
          1. Installing TestNG for Eclipse
          2. Modifying the index.jsp file
          3. Modifying the POM file
          4. Creating a user acceptance test case
          5. Generating the testng.xml file
        8. Continuous Delivery in action
          1. Committing and pushing changes on the feature1 branch
          2. Jenkins Continuous Delivery pipeline in action
          3. Exploring the job to perform deployment in the testing server
          4. Exploring the job to perform a user acceptance test
          5. Exploring the job for performance testing
        9. Summary
      14. 7. Continuous Deployment Using Jenkins
        1. What is Continuous Deployment?
          1. How Continuous Deployment is different from Continuous Delivery
          2. Who needs Continuous Deployment?
          3. Frequent downtime of the production environment with Continuous Deployment
        2. Continuous Deployment Design
          1. The Continuous Deployment pipeline
            1. Pipeline to poll the feature branch
              1. Jenkins job 1
              2. Jenkins job 2
            2. Pipeline to poll the integration branch
              1. Jenkins job 1
              2. Jenkins job 2
              3. Jenkins job 3
              4. Jenkins job 4
              5. Jenkins job 5
              6. Jenkins job 6
              7. Jenkins job 7
          2. Toolset for Continuous Deployment
        3. Configuring the production server
          1. Installing Java on the production server
          2. Installing the Apache Tomcat server on the production server
        4. Jenkins configuration
          1. Configuring Jenkins slaves on the production server
        5. Creating the Jenkins Continuous Deployment pipeline
          1. Modifying the existing Jenkins job
            1. Modifying the Jenkins job that performs the performance test
          2. Creating a Jenkins job to merge code from the integration branch to the production branch
          3. Creating the Jenkins job to deploy code to the production server
        6. Creating a nice visual flow for the Continuous Delivery pipeline
        7. Continuous Deployment in action
          1. Jenkins Continuous Deployment pipeline flow in action
          2. Exploring the Jenkins job to merge code to the master branch
          3. Exploring the Jenkins job that deploys code to production
        8. Summary
      15. 8. Jenkins Best Practices
        1. Distributed builds using Jenkins
          1. Configuring multiple build machines using Jenkins nodes
          2. Modifying the Jenkins job
          3. Running a build
        2. Version control Jenkins configuration
          1. Using the jobConfigHistory plugin
          2. Let's make some changes
        3. Auditing in Jenkins
          1. Using the Audit Trail plugin
        4. Notifications
          1. Installing HipChat
          2. Creating a room or discussion forum
          3. Integrating HipChat with Jenkins
          4. Installing the HipChat plugin
          5. Configuring a Jenkins job to send notifications using HipChat
          6. Running a build
        5. Best practices for Jenkins jobs
          1. Avoiding scheduling all jobs to start at the same time
            1. Examples
          2. Dividing a task across multiple Jenkins jobs
          3. Choosing stable Jenkins releases
          4. Cleaning up the job workspace
            1. Using the Keep this build forever option
          5. Jenkins themes
        6. Summary
      16. Index