Folders Template

Folders are another Jenkins Enterprise feature, described in another document. It allows you to group related jobs and organize them in a hierarchical way, as you’d do with files and directories on a file system.

As a container of jobs, a folder template is an useful way to define a set of jobs that follow enterprise rules and best practices. For example, a single folder template could instantly provision a set of jobs that implement your organization’s best practice, for example (1) a CI job that builds the tip of the repository every time a commit is made, (2) a continuous inspection nightly job to populate a sonar server with code quality metrics, and (3) a continuous deployment job to push successful builds to a demo server for dogfood eating.

A folder template can be also useful to clarify the “flavor” of a folder and how it’s supposed to be used. For example, you might have a template for a product, and which contains branch folders that are templates themselves (say because you need multiple jobs for one branch.) Such modeling enables you to now capture relationship between your products as model attributes, which can then translate into lower level configuration, such as trigger relationship.

What a folder template controls and what it doesn’t

Folder template controls the configuration of a folder itself (that is, everything that appears in the configuration page of the folder), such as the name, the icon, views, and access control matrix.

A folder template also allows you to specify a set of activities that are to be performed when a new instance of the template is created, such as creating jobs inside the new folder, as can be seen in the screenshot below:

Figure 10.15. Folder Templates

template folders

But beyond the initial creation, jobs inside a folder aren’t controlled by templates. So with sufficient permissions, users can add/remove jobs and the template change will not void those changes. If this is undesirable and you prefer to lock things down further, you can use job templates for jobs in a folder template (to restrict the configuration freedom) and use access control to prevent creation/deletion (see RBAC documentation for more details.)

Folder features that work well with templates

There are several features in the folder plugin that work really nicely when combined with a folder template.

Restrict child type in a folder

A folder can be configured to restrict the kind of items that it can contain. When you define a folder template, this is useful way of strengthening the flavor of a folder. For example, you can say that a product folder template can only contain branch folder templates.

Environment variables

A folder can be configured to define a set of environment variables that are automatically made visible to all the builds inside the folder. This is one of the primary ways to use the template attributes and have them affect what goes on inside a folder. In the earlier example of a folder template that represents a branch, you can define the environment variable called BRANCH, and all your jobs can refer to this variable to choose where to check out the code from.

Model attribute list view column

The template plugin adds a new list view column extension, which lets you display values of the specified attribute from items in the container.

This list view column is useful when you have a folder (or a view) that contains items created from job templates / folder templates. For example, if you have a folder template that represents a product, which in turn contains folder templates that represent branches, you can show the name of the branches in a list view inside the product.

This can be further combined with the “computed value” attribute type to further control what to display.