Extending Jenkins - Donald Simpson - E-Book

Extending Jenkins E-Book

Donald Simpson

0,0
27,59 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

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.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 152

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Extending Jenkins
Credits
About the Author
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Preparatory Steps
Getting started with Jenkins
Extending the basic setup
Jenkins evolution
Continuous Integration with Jenkins
Summary
2. Automating the Jenkins UI
Use case scenario 1 – a large number of jobs
Use case scenario 2 – multiple hosts
Use case scenario 3 – helping your users through UI automation
Use case scenario 4 – UI tweaks
Summary
3. Jenkins and the IDE
Eclipse and Mylyn
Installing Mylyn
Mylyn and Jenkins configurations
IntelliJ IDEA and Jenkins build connectors
NetBeans
Summary
4. The API and the CLI
Creating an Information Radiator with the Jenkins XML API
Getting the information from Jenkins
Automating the job
Radiating the information
Jenkins as a web server – the userContent directory
The Jenkins CLI
How to set it up
How to use it
Triggering remote jobs via the CLI
Updating Jenkins configuration
Summary
5. Extension Points
A brief history of Jenkins plugins
Interfaces
Abstract classes
Abstraction and interfaces
Singletons
Declaring an extension in Jenkins
Summary
6. Developing Your Own Jenkins Plugin
An introduction to Maven
Installing Maven
Summary
7. Extending Jenkins Plugins
Where to start?
Looking at the list of existing plugins
A new build type required
Loading and building our starting point
The Builder class and Stapler
Jelly and Jenkins
Help
Properties files and Messages
The POM file
Plugin progress
Summary
8. Testing and Debugging Jenkins Plugins
Running tests with Maven
Debugging Jenkins
Server debugging – a quick recap
Debugging with IntelliJ
Debugging with Eclipse
mvnDebug
The Jenkins Logger Console
Summary
9. Putting Things Together
The Jenkins script console and Groovy
Groovy and Gradle as alternatives
Jenkins and Docker
Docker in Jenkins
Jenkins in Docker
Jenkins and Android
Jenkins and iOS
Keeping your Jenkins version and plugins up to date
Summary
Index

Extending Jenkins

Extending Jenkins

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: December 2015

Production reference: 1171215

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78528-424-3

www.packtpub.com

Credits

Author

Donald Simpson

Reviewer

Tony Sweets

Commissioning Editor

Amarabha Banerjee

Acquisition Editor

Indrajit Das

Content Development Editor

Riddhi Tuljapurkar

Technical Editor

Menza Mathew

Copy Editor

Kausambhi Majumdar

Project Coordinator

Sanchita Mandal

Proofreader

Safis Editing

Indexer

Tejal Daruwale Soni

Graphics

Abhinash Sahu

Production Coordinator

Melwyn Dsa

Cover Work

Melwyn Dsa

About the Author

Donald Simpson is an information technology consultant based in Scotland, UK.

He specializes in helping organizations improve the quality and reduce the cost of software development through the adoption of process automation and Agile methodologies.

Starting out as a Java developer, Donald's interest in application servers, networking, and automation led him to a career as a build engineer. He remains highly technical and hands-on and enjoys learning about new technologies and finding ways to automate and improve manual processes.

He can be reached at www.donaldsimpson.co.uk.

I would like to thank my wife, Clair, and my children, Freya and Lyla, for their support and encouragement throughout my career and the writing of this book.

About the Reviewer

Tony Sweets has over 20 years of experience in software development, with most of it in Java and Java-based technologies. Known as the "Tools" guy before there was any concept of DevOps, he also has a passion for setting up and managing hardware and networks. Introduced to Agile development very early on, he has set up and maintained his company's continuous integration system that ranges from Cruise Control to Hudson, and now Jenkins. He is currently a software architect in the payments field and has been working in financial services for over 17 years.

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

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 <[email protected]>, 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 <[email protected]> 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 <[email protected]>, and we will do our best to address the problem.

Chapter 1. Preparatory Steps

In this first chapter, we will start off by looking at Jenkins from several different perspectives; how to obtain and run it, some of the ways and the reasons people use it, and what it provides to them. In doing so, we will take a look at some standard use cases and examine how a Jenkins installation will often evolve over a period of time—typically starting off with only the basic installation and core features, then progressively becoming more customized and advanced with different types of extensions. We will start off with "ready-made" plugins, and then progress towards extending these before looking at how to develop your own plugins.

We will then summarize the high-level aims of this book, and give the details of what you should hopefully gain from them.

We will provide an overview of the various tools and the environment setup that you will need in order to run the practical examples covered in the subsequent chapters, and we will review the best practices of Continuous Integration (CI) by identifying some of the ways that Jenkins can be used to achieve them.

Throughout this book, it is assumed that you already have some working knowledge of Jenkins, so we will not spend much time covering the basics, such as installing and starting Jenkins, or detailing the usage of standard features and core functions.

If you would like more details on these topics, there are numerous helpful tutorials and examples available online; the Use Jenkins section of the Jenkins homepage, https://jenkins-ci.org, is often a good starting point for help with general setup and usage questions.

Getting started with Jenkins

As a Java application, Jenkins can be installed and run in different ways depending on your requirements, personal preferences, and the environment that you are running it in.

The simplest and easiest approach to quickly get Jenkins up and running is by setting up Java, downloading the latest Jenkins WAR file from the Jenkins homepage (www.jenkins-ci.org), and then simply starting it from the command line like this:

java –jar jenkins.war

The following figure demonstrates the use of this approach by running just two simple commands:

wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war:

This command downloads the latest version of Jenkins from the main site.

wget is a Linux utility that fetches files from the Web—if you are on a platform that does not have wget, you can simply save the link (the jenkins.war file) via your browser to a working directory instead.

The URL is obtained by copying the Latest & Greatest link from the homepage at https://jenkins-ci.org/. Note that there is also an option to download and use the Long-Term Support release instead of the current, latest, and greatest, as explained here: https://wiki.jenkins-ci.org/display/JENKINS/LTS+Release+Line.

This is preferable for more conservative installations, where stability is more important than having latest features.

java –jar jenkins.war: