Book Image

Extending Jenkins

By : Donald Simpson
Book Image

Extending Jenkins

By: Donald Simpson

Overview of this book

Jenkins CI is the leading open source continuous integration server. It is written in Java and has a wealth of plugins to support the building and testing of virtually any project. Jenkins supports multiple Software Configuration Management tools such as Git, Subversion, and Mercurial. This book explores and explains the many extension points and customizations that Jenkins offers its users, and teaches you how to develop your own Jenkins extensions and plugins. First, you will learn how to adapt Jenkins and leverage its abilities to empower DevOps, Continuous Integration, Continuous Deployment, and Agile projects. Next, you will find out how to reduce the cost of modern software development, increase the quality of deliveries, and thereby reduce the time to market. We will also teach you how to create your own custom plugins using Extension points. Finally, we will show you how to combine everything you learned over the course of the book into one real-world scenario.
Table of Contents (16 chapters)
Extending Jenkins
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

Jenkins provides many interfaces and extension points to enable users to customize and extend its functionality. In this book, we will explore these interfaces in depth and provide practical real-world examples that will take your usage of Jenkins to the next level.

In this book, you will learn how to develop and test your own Jenkins plugin, find out how to set up fully automated build pipelines and development processes, discover how to interact with the API and CLI, and how to enhance the user interface.

What this book covers

Chapter 1, Preparatory Steps, will cover the initial setup steps—getting your development environment set up, an overview of Jenkins and some options to install and run it as well as extend the basic setup. We will also review the principles of Continuous Integration, which are explored in greater detail later.

Chapter 2, Automating the Jenkins UI, will discuss how several common issues and bottlenecks may be alleviated through the automation and adaptation of the Jenkins frontend. Here, we will look at four fairly typical use cases, identify the root cause of the issues, and propose some possible improvements that can be made through the alteration and automation of the GUI.

Chapter 3, Jenkins and the IDE, builds on the Continuous Integration principals that we looked at earlier and provides an introduction to the Mylyn project.

It then details how to set up a process that enables developers to interact with Jenkins directly from within their IDE. A selection of examples covers Eclipse, NetBeans, and IntelliJ.

Chapter 4, The API and the CLI, illustrates how we can automate and extend Jenkins through its API and CLI. In this chapter, we will illustrate how to use these interfaces by working through the high-level "building blocks" of an example "Information Radiator" project.

This chapter will explain how to create a dynamic application that consumes information from Jenkins via its exposed interfaces.

We will also review other ways in which you could extend Jenkins via the CLI—by kicking off jobs and making other changes to Jenkins automatically and remotely.

Chapter 5, Extension Points, introduces many important concepts that provide a foundation for the Jenkins Extension points topics in the subsequent chapters. We will run through Java interfaces, Design by Contract, abstract classes, and Singletons. We will then take a look at how these patterns are used in the real world when we define our own Extension Point in Jenkins.

Chapter 6, Developing Your Own Jenkins Plugin, will combine the skills, concepts, and tools from the preceding chapters to build our first Jenkins plugin.

We will take a look at Maven and learn how to set it up and use it for Jenkins plugin development. We will then create our first Jenkins plugin, learn how to install it locally, and then learn how to quickly make, build, and deploy subsequent changes using Maven.

Chapter 7, Extending Jenkins Plugins, makes use of a simple plugin with the "Hello world" functionality we created in the previous chapter to keep the focus on getting to grips with the processes and tools. This chapter takes a look at the best way to get started with adding your own implementations. You will learn how to reuse existing code and functionality and understand how and where to find them.

After taking a look at some existing plugins and using those as examples, we will then take a detailed look at some of the additional resources and technologies you could take advantage of in your own projects.

Chapter 8, Testing and Debugging Jenkins Plugins, explains how to test and debug your own code and how to apply the same approach to existing plugins for troubleshooting.

It covers running tests with Maven, examines some existing tests from a popular plugin, and uses these to demonstrate how you can adapt these approaches to suit your own projects.

We will also take a look at debugging live code through the IDE and show how to integrate these useful functions into popular development IDEs. The final section of this chapter will introduce the inbuilt Jenkins Logger Console.

Chapter 9, Putting Things Together, takes a look at how Jenkins can be extended to work with other technologies and languages. We will start off with a look at the Jenkins Scripting console and see how useful it can be when combined with some Groovy scripting by providing some examples. We will then discuss developing applications using Groovy, Grails, and Gradle as possible alternatives to Maven and Java. The final part of this chapter covers Jenkins and Docker and then discusses how to set up build and deployment pipelines for iOS and Android development.

What you need for this book

The reader is assumed to have some working knowledge of Jenkins and programming in general, an interest in learning the different options to take things to the next level, and an inclination to understand how to customize and extend Jenkins to suit their requirements and needs.

Who this book is for

This book is aimed primarily at developers and administrators who are interested in taking their interaction and usage of Jenkins to the next level—extending it to fit their needs, interacting with Jenkins via its interfaces, and developing their own custom unit-tested plugins.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

<html>
  <head>
    <meta http-equiv="refresh" content="5">
    <style type="text/css">

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<html>
  <head>
    <meta http-equiv="refresh" content="5">
    <style type="text/css">

Any command-line input or output is written as follows:

java -jar jenkins-cli.jar -s http://minty:8080/ get-job VeryBasicJob

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Note that the http://jenkins-ci.org/ home page also hosts Native Installers for many popular operating systems under the Native packages column."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.