Chapter 10. Template Plugin


The template plugin gives the Jenkins administrator the opportunity to provide users a simplified and directed experience for configuring jobs, in “domain specific” terms that make sense to your organization. With plain-vanilla Jenkins, users can get confused with a large number of advanced options and switches that they don’t need, resulting in less than optimal user experience and mis-configured jobs. The template plugin is useful in situations like this, as it allows the administrator to define a few parameters that users need to fill in, while the administrator controls precisely how these map to the fully general configuration, in one place. In this way, most users of your organization will be shielded from the full generality of Jenkins, and the administrator will be able to enforce the consistency, best practices, and enterprise rules without overhead.

Another typical use case of the template plugin is when you have a large number of similar-looking jobs that only differ in a few aspects, such as jobs building different branches of the same product, or teams building a large number of components in a uniform way. When you change a template, all the uses of the template get updated instantaneously, so the administrator doesn’t have to manually update a large set of jobs to fix a shell script, nor does he need to rely on techniques like the Groovy console for bulk update.

Yet another way to think of the template plugin is that it’s like writing a plugin without writing a program. If you think about the Ant plugin, it lets you configure Ant invocation with a number of text fields that talk in the domain-specific terms of Ant (such as targets, properties, VM options, etc.), as opposed to the single text area that is the shell script. Or with the Maven plugin, you get a whole project type specifically for invoking Maven, instead of using the generic free-style project and invoking Maven from it. With the template plugin, you can do these things without actually writing code (or writing only some small Groovy snippets).

The template plugin was introduced in Nectar 11.10.