Skip to content

Commit ea806ed

Browse files
author
Ken Erwin
committed
Added templates lesson
1 parent 162de6c commit ea806ed

File tree

10 files changed

+136
-71
lines changed

10 files changed

+136
-71
lines changed

Vagrantfile

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
layout: post
3+
title: "CCJPE: Jenkins Templates"
4+
date: 2017-04-22 12:00:00 -0500
5+
categories: Jenkins
6+
permalink: lessons/jenkins-templates
7+
excerpt: "Use templates to simplify job creation!"
8+
weight: 15
9+
image: 'jenkinscourse.png'
10+
difficulty: easy
11+
12+
---
13+
{% include youtube.html id="26th8achUYw" %}
14+
{% include hired2.html %}
15+
16+
1. Table of Contents
17+
{:title="Table of Contents"}
18+
{:toc}
19+
20+
Cloud Config File Downloads
21+
---------------------------
22+
* [Jenkins Master01](https://www.devopslibrary.com/scripts/master01.yaml)
23+
24+
Introduction
25+
------------
26+
Welcome to the DevOps Library! This is Samantha, and in today's episode we're
27+
going to cover how to use Jenkins templates. Unfortunately, the template plugin
28+
itself IS only available to Jenkins enterprise users, but if that's an option
29+
for you it does make it much easier to simplify Jenkins job creation.
30+
31+
One common use case is when you have a bunch of nearly identical jobs with a
32+
couple of minor differences. Let's say one day you need to modify something on
33+
all of them. Normally you'd have to edit each job individually, but if they
34+
were built using the same template, you could simply modify it and every job,
35+
builder, or folder based on the template would update instantly!
36+
37+
In some cases Jenkins Job builder is a better option, but the template plugin
38+
excels if your goal is to make it easier to create jobs. You can also
39+
look at it as a way to implement new functionality that would typically require
40+
writing a plugin, but without the need to do any actual coding.
41+
42+
Don't worry, by the end of this lesson you'll know how to do that and more, but
43+
first we'd like to give a quick shout out to [Hired.com](hired.com/devopslibrary)
44+
for being kind enough to sponsor our Jenkins course.
45+
46+
Creating a Template
47+
----------------------
48+
Ok, back to our tutorial. First, let's create a new build step template for
49+
downloading files. Click "New Item", type "Download" for the name, then select
50+
"Builder Template" for the item type. Now go ahead and click "ok" to bring up
51+
the template configuration page.
52+
53+
Before we do anything, let's think about what we want our template to do.
54+
Since this is a "builder template", it's going to show up on the list of
55+
builders of any freestyle jobs we set up, right along with "Execute shell script"
56+
and all the other standard Jenkins builders. For this template, let's make a
57+
build step that downloads a file to our workspace when given a URL.
58+
59+
It's actually really easy to configure. First, let's add an attribute with an
60+
id of "url".
61+
62+
An easy way to think of an attribute is as a template parameter.
63+
64+
We'll stick with "Text-field" for the type, then feel free to add an inline help
65+
description if you'd like.
66+
67+
Next, we need to configure the transformer, which is used to tell Jenkins how
68+
our builder works. If you're comfortable with groovy, you can do just
69+
about anything you'd like here, but for our example we'll go with a generated
70+
shell script.
71+
72+
Type: wget, followed by a dollar sign and the name of our attribute, URL.
73+
Since the script section is actually a groovy template, Jenkins will populate
74+
the URL in our transformer with the URL provided by the user in the attribute.
75+
Pretty cool huh? Alright, go ahead and save the template, it's time to try it out!
76+
77+
Create a new item again, but this time name it whatever you'd like, and
78+
select "Freestyle project" for the type. Click ok, then scroll down to the
79+
bottom until you see "Add Build Step". Look at the dropdown, there's our new
80+
build step we just created! Feel free to type any URL that you'd like then run the
81+
job. Pretty cool huh?
82+
83+
Summary
84+
-------
85+
While I know our example was pretty simple, keep in mind you're not limited to
86+
templating build steps. You can create auxiliary templates for creating nested
87+
attribute structures, publisher templates, or even an entire job template.
88+
89+
As we mentioned earlier, one of the best things about using templates is that any
90+
time you modify one, it'll automatically update anything else built off of it.
91+
For example, let's say you create a job template for testing... a Chef cookbook.
92+
A few months later the team wants to add a new linter to every cookbook testing job.
93+
In this example, we only have to modify a single template and we're done, making it
94+
super easy to maintain large Jenkins environments as well as being able to share
95+
best practices between jobs.
96+
97+
Hopefully this lesson has helped you understand when and why the template plugin
98+
can be helpful, thank you so much for watching!
99+
100+
--------------------
101+
[Subscribe to our YouTube channel](https://www.youtube.com/channel/UCOnioSzUZS-ZqsRnf38V2nA?sub_confirmation=1) or follow [DevOpsLibrary on Twitter](https://twitter.com/intent/user?screen_name=devopslibrary).
102+
103+
{% include subscribe.html %}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.5:42936df5-0838-4739-ac68-ae2119502e04
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1492902061
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
390460725
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
42936df5-0838-4739-ac68-ae2119502e04
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
35dee9ce83194450927acde6264dab45
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIIEpQIBAAKCAQEAr1IuF4XwgfmtOb3PaeXWHG9OBa80aYyErqBAvAZ4MMDWuDxt
3+
S8NFDjMHG/CvHYmDLcn6I/t5QCOm9yqEjPu+J5r4p9Kh3NW21vpcX+f9VXrTQWvV
4+
friMD31Wn89NG/Q0QPNldhBgxoEFcj8VDcBc/DxK9jPxAhYlgymxq+Y8JEFoFUx0
5+
tpUGb0s1N0TSSeFZaBtRq8fsZIiiWA0dWGIbG/+03ZpT89jEywHkJIFwaTMPHxtM
6+
La5k9rNAigjcuhqHnAgmpNEoHqxNTS//LsP37KiFJTkbTbTzDhrPwmCMhATp5/zl
7+
ZC0T0TBtoUqtS9UHYEhdSOWuMnbEjMwG7QMfrwIDAQABAoIBAQCpRcNS2vM3ywVB
8+
ds5IBK0RjzXZryv/rLh+kiNuZyCskcO+5jjwqXyHFSWMCHpLHnYVQ6nMDAUptEKE
9+
6fxI0tbqDmp+PpQhUAbU0a1Wu/qRCaHmzGK5kx1H51A3xENC9iltfJM9xtppTjEf
10+
+WAugshEkUIfLE9KIG/fj+YHfqgap6LLpj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PGipx5BVH7Hagv+U3hs/4qJ/y3mc964FfbfGoexQ=
27+
-----END RSA PRIVATE KEY-----
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"virtualbox":{"/vagrant":{"guestpath":"/vagrant","hostpath":"/Users/kerwin/Documents/devopslibrary.github.io/vagrant/jenkins","disabled":false,"__vagrantfile":true}}}

vagrant/jenkins/ubuntu-xenial-16.04-cloudimg-console.log

Whitespace-only changes.

0 commit comments

Comments
 (0)