The job-dsl-plugin allows the programmatic creation of projects using a DSL. Pushing job creation into a script allows you to automate and standardize your Jenkins installation, unlike anything possible before.

Summary

Jenkins is a wonderful system for managing builds, and people love using its UI to configure jobs. Unfortunately, as the number of jobs grows, maintaining them becomes tedious, and the paradigm of using a UI falls apart. Additionally, the common pattern in this situation is to copy jobs to create new ones, these "children" have a habit of diverging from their original "template" and consequently it becomes difficult to maintain consistency between these jobs.

The Jenkins job-dsl-plugin attempts to solve this problem by allowing jobs to be defined with the absolute minimum necessary in a programmatic form, with the help of templates that are synced with the generated jobs. The goal is for your project to be able to define all the jobs they want to be related to their project, declaring their intent for the jobs, leaving the common stuff up to a template that were defined earlier or hidden behind the DSL.

Configuration

After installing the plugin, you'll get a new Build Step entry named "Process Job DSLs". Type the DSL directly in the text box, or point to a file in the workspace.

Basics

The DSL allows the definition of a job, and then offers a useful set of functions to configure common Jenkins items. A configure is available to give direct access to the config.xml before generating the job. The script is groovy code, which can be very powerful. Here's an example to create a job for each branch in a git repo:

Roadmap

Gradle plugin, for creation of jobs from Gradle

Additional methods to cover the most common configuration items.

About

This plugin is started as a hack-a-thon at the Java Posse Roundup#457. It was primarily developed for use at Netflix, but is now used at a wide range of companies and projects. It is licensed under Apache License, Version 2.0.

Changelog

13 Comments

Thanks for this great plugin. I'm wondering if there's a way to fail a DSL Script build-step. I tried returning false at the top of the script and that didn't seem to have any effect (the DSL still was executed).

I see the Job DSL plug is updated to work with a lot of different plugins. I didn't see the "Hidden Parameter" plugin on the list. Could that be added in the next round, please? I want to inject some parameters into the job that will be created but I don't want those parameters visible (or changed) by the user. I don't want to inject them as environment variables because I intend to pass a parameters object on a build flow's build command: build(myParams,"myJob").

For now I suppose, I'll have to inject them as environment variables and then pick them up and add them to a parameters collection before passing it on to the build statement. It would be far more convenient to just generate the job directly from the DSL as a hidden parameter.