You are previewing Jenkins: The Definitive Guide.

Jenkins: The Definitive Guide

Cover of Jenkins: The Definitive Guide by John Ferguson Smart Published by O'Reilly Media, Inc.
  1. Jenkins: The Definitive Guide
    1. SPECIAL OFFER: Upgrade this ebook with O’Reilly
    2. Foreword
    3. Preface
      1. Audience
      2. Book Layout
      3. Jenkins or Hudson?
      4. Font Conventions
      5. Command-Line Conventions
      6. Contributors
      7. The Review Team
      8. Book Sponsors
      9. Using Code Examples
      10. Safari® Books Online
      11. How to Contact Us
      12. Acknowledgments
    4. 1. Introducing Jenkins
      1. Introduction
      2. Continuous Integration Fundamentals
      3. Introducing Jenkins (née Hudson)
      4. From Hudson to Jenkins—A Short History
      5. Should I Use Jenkins or Hudson?
      6. Introducing Continuous Integration into Your Organization
      7. Where to Now?
    5. 2. Your First Steps with Jenkins
      1. Introduction
      2. Preparing Your Environment
      3. Starting Up Jenkins
      4. Configuring the Tools
      5. Your First Jenkins Build Job
      6. Your First Build Job in Action
      7. More Reporting—Displaying Javadocs
      8. Adding Code Coverage and Other Metrics
      9. Conclusion
    6. 3. Installing Jenkins
      1. Introduction
      2. Downloading and Installing Jenkins
      3. Preparing a Build Server for Jenkins
      4. The Jenkins Home Directory
      5. Installing Jenkins on Debian or Ubuntu
      6. Installing Jenkins on Redhat, Fedora, or CentOS
      7. Installing Jenkins on SUSE or OpenSUSE
      8. Running Jenkins as a Stand-Alone Application
      9. Running Jenkins Behind an Apache Server
      10. Running Jenkins on an Application Server
      11. Memory Considerations
      12. Installing Jenkins as a Windows Service
      13. What’s in the Jenkins Home Directory
      14. Backing Up Your Jenkins Data
      15. Upgrading Your Jenkins Installation
      16. Conclusion
    7. 4. Configuring Your Jenkins Server
      1. Introduction
      2. The Configuration Dashboard—The Manage Jenkins Screen
      3. Configuring the System Environment
      4. Configuring Global Properties
      5. Configuring Your JDKs
      6. Configuring Your Build Tools
      7. Configuring Your Version Control Tools
      8. Configuring the Mail Server
      9. Configuring a Proxy
      10. Conclusion
    8. 5. Setting Up Your Build Jobs
      1. Introduction
      2. Jenkins Build Jobs
      3. Creating a Freestyle Build Job
      4. Configuring Source Code Management
      5. Build Triggers
      6. Build Steps
      7. Post-Build Actions
      8. Running Your New Build Job
      9. Working with Maven Build Jobs
      10. Using Jenkins with Other Languages
      11. Conclusion
    9. 6. Automated Testing
      1. Introduction
      2. Automating Your Unit and Integration Tests
      3. Configuring Test Reports in Jenkins
      4. Displaying Test Results
      5. Ignoring Tests
      6. Code Coverage
      7. Automated Acceptance Tests
      8. Automated Performance Tests with JMeter
      9. Help! My Tests Are Too Slow!
      10. Conclusion
    10. 7. Securing Jenkins
      1. Introduction
      2. Activating Security in Jenkins
      3. Simple Security in Jenkins
      4. Security Realms—Identifying Jenkins Users
      5. Authorization—Who Can Do What
      6. Auditing—Keeping Track of User Actions
      7. Conclusion
    11. 8. Notification
      1. Introduction
      2. Email Notification
      3. More Advanced Email Notification
      4. Claiming Builds
      5. RSS Feeds
      6. Build Radiators
      7. Instant Messaging
      8. IRC Notification
      9. Desktop Notifiers
      10. Notification via Notifo
      11. Mobile Notification
      12. SMS Notification
      13. Making Noise
      14. Extreme Feedback Devices
      15. Conclusion
    12. 9. Code Quality
      1. Introduction
      2. Code Quality in Your Build Process
      3. Popular Java and Groovy Code Quality Analysis Tools
      4. Reporting on Code Quality Issues with the Violations Plugin
      5. Using the Checkstyle, PMD, and FindBugs Reports
      6. Reporting on Code Complexity
      7. Reporting on Open Tasks
      8. Integrating with Sonar
      9. Conclusion
    13. 10. Advanced Builds
      1. Introduction
      2. Parameterized Build Jobs
      3. Parameterized Triggers
      4. Multiconfiguration Build Jobs
      5. Generating Your Maven Build Jobs Automatically
      6. Coordinating Your Builds
      7. Build Pipelines and Promotions
      8. Conclusion
    14. 11. Distributed Builds
      1. Introduction
      2. The Jenkins Distributed Build Architecture
      3. Master/Slave Strategies in Jenkins
      4. Associating a Build Job with a Slave or Group of Slaves
      5. Node Monitoring
      6. Cloud Computing
      7. Using the CloudBees DEV@cloud Service
      8. Conclusion
    15. 12. Automated Deployment and Continuous Delivery
      1. Introduction
      2. Implementing Automated and Continuous Deployment
      3. Deploying to an Application Server
      4. Conclusion
    16. 13. Maintaining Jenkins
      1. Introduction
      2. Monitoring Disk Space
      3. Monitoring the Server Load
      4. Backing Up Your Configuration
      5. Archiving Build Jobs
      6. Migrating Build Jobs
      7. Conclusion
    17. A. Automating Your Unit and Integration Tests
      1. Automating Your Tests with Maven
      2. Automating Your Tests with Ant
    18. Index
    19. About the Author
    20. Colophon
    21. SPECIAL OFFER: Upgrade this ebook with O’Reilly
O'Reilly logo

Configuring Your JDKs

Historically, one of the most common uses of Jenkins has been to build Java applications. So Jenkins naturally provides excellent built-in support for Java.

By default, Jenkins will build Java applications using whatever version of Java it finds on the system path, which is usually the version that Jenkins itself is running under. However, for a production build server, you will probably want more control than this. For example, you may be running your Jenkins server under Java 6, for performance reasons. However, your production server might be running under Java 5 or even Java 1.4. Large organizations are often cautious when it comes to upgrading Java versions in their production environments, and some of the more heavyweight application servers on the market are notoriously slow to be certified with the latest JDKs.

In any case, it is always a wise practice to build your application using a version of Java that is close to the one running on your production server. While an application compiled with Java 1.4 will usually run fine under Java 6, the inverse is not always true. Or you may have different applications that need to be built using different versions of Java.

Jenkins provides good support for working with multiple JVMs. Indeed, Jenkins makes it very easy to configure and use as many versions of Java as you want. Like most system-level configuration, we do this in the Configure System screen (see Figure 4-2). Here, you will find a section called JDK which allows you to manage the JDK installations you need Jenkins to work with.

The simplest way to declare a JDK installation is simply to supply an appropriate name (which will be used to identify this Java installation later on when you configure your builds), along with the path to the Java installation directory (the same path you would use for the JAVA_HOME variable), as shown in Figure 4-5. Although you need to type the path manually, Jenkins will check in real time both that the directory exists and that it looks like a valid JDK directory.

JDK configuration in Jenkins

Figure 4-5. JDK configuration in Jenkins

You can also ask Jenkins to install Java for you. In this case, Jenkins will download the JDK installation and install a copy on your machine (see Figure 4-6). The first time a build needs to use this JDK, Jenkins will download and install the specified version of Java into the tools directory in the Jenkins home directory. If the build is running on a new build agent that doesn’t have this JDK installed, it will download and install it onto the build agent machine as well.

This is also a great way to configure build agents. As we’ll see later on in the book, Jenkins can delegate build jobs to other machines, or build agents. A build agent (or “slave”) is simply another computer that Jenkins can use to run some of its builds. If you use Jenkins’s Install automatically option, you don’t need to manually install all the JDK versions you need on the build agent machines—Jenkins will do it for you the first time it needs to.

By default, Jenkins proposes to download the JDK from the Oracle website. If your Jenkins installation is behind a proxy server, you may need to configure your proxy settings to ensure that Jenkins can access the external download sites (see Configuring a Proxy). Another option is to provide a URL pointing to your own internal copy of the JDK binaries (either in the form of a ZIP or a GZip-compressed TAR file), stored on a local server within your organization. This lets you provide standard installations on a local server and makes for faster automatic installations. When you use this option, Jenkins also lets you specify a label, which will restrict the use of this installation to the build notes with this label. This is a useful technique if you need to install a specific version of a tool on certain build machines. The same approach can also be used for other build tools (such as Maven and Ant).

Installing a JDK automatically

Figure 4-6. Installing a JDK automatically

The automatic installer will not work in all environments (if it can’t find or identify your operating system to its satisfaction, for example, the installation will fail), but it is nevertheless a useful and convenient way to set up new build servers or distributed build agents in a consistent manner.

The best content for your career. Discover unlimited learning on demand for around $1/day.