Job DSL Plugin

Skip to end of metadata
Go to start of metadata

Plugin Information

Plugin ID job-dsl Changes In Latest Release
Since Latest Release
Latest Release
Latest Release Date
Required Core
Dependencies
1.22
Apr 05, 2014
1.480
ant (version:1.2, optional)
cloudbees-folder (version:4.2, optional)
credentials (version:1.9.4, optional)
javadoc (version:1.1, optional)
maven-plugin (version:1.480, optional)
Source Code
Issue Tracking
Maintainer(s)
GitHub
Open Issues
(not specified)
Usage Installations 2013-Apr 205
2013-May 248
2013-Jun 286
2013-Jul 351
2013-Aug 374
2013-Sep 408
2013-Oct 512
2013-Nov 550
2013-Dec 559
2014-Jan 662
2014-Feb 749
2014-Mar 827

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.

A bulk of the documentation for this plugin is in the GitHub wiki

Please join the mailing list ( https://groups.google.com/d/forum/job-dsl-plugin) for any user or developer questions.

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:

def project = 'quidryan/aws-sdk-test'
def branchApi = new URL("https://api.github.com/repos/${project}/branches")
def branches = new groovy.json.JsonSlurper().parse(branchApi.newReader())
branches.each {
    def branchName = it.name
    job {
        name "${project}-${branchName}".replaceAll('/','-')
        scm {
            git("git://github.com/${project}.git", branchName)
        }
        steps {
            maven("test -Dproject.name=${project}/${branchName}")
        }
    }
}

Features

  • DSL - Scriptable via Groovy
  • DSL - Direct control of XML, so that anything possible in a config.xml is possible via the DSL
  • DSL - Helper methods for common job configurations, e.g. scm, triggers, build steps
  • Plugin - DSL can be put directly in a job
  • Plugin - DSL can be put into SCM and polled using standard SCM triggering
  • Plugin - Multiple DSLs can be referenced at a time
  • Plugin - Tracks Templates used, will update derivative jobs when template is changed

Usage

See the wiki for specific steps and other examples.

  1. Create your set of Jenkins jobs which will serve as the templates (It is a good idea to use a naming convention for these jobs which clearly indicates that these are templates)
  2. Create a Jenkins Job using the Free-style project style to run your DSL Scripts. This is called a "Seed" job.
  3. Configure the seed job, by adding a "Build Step" of type "Process Job DSLs" and paste in the body of the DSL.
  4. Run the seed to generate your new jobs from your script. When successful, and the "build result" page will list the jobs which have been successfully created.
  5. Finally, it is good practice to organise your Jenkins UI with some new tabs so that the management and template jobs are not the first thing a user sees when they login

The tutorial provides explicit steps to use the plugin.

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. It is now primarily developed for use at Netflix. It is Licensed under Apache.

Labels

Edit
plugin-builder plugin-builder Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Add Comment