Fork me on GitHub

grunt-jenkins

npm version
Build Status
Code Climate
dependencies Status
devDependencies Status

Manage Jenkins with Grunt

Getting Started

Install this grunt plugin next to your project's Gruntfile.js with:

$ npm install grunt-jenkins --save-dev

Gruntfile.js

Jenkins is not authenticated

module.exports = function(grunt) {
  grunt.initConfig({
    // ...
    jenkins: {
      serverAddress: 'http://localhost:8080',
      pipelineDirectory: 'jenkins-pipeline'   // optional, default: 'pipeline'
    }
  });
  grunt.loadNpmTasks('grunt-jenkins');
  // ...
};

Jenkins is authenticated and credentials are in .netrc (preferred)

module.exports = function(grunt) {
  grunt.initConfig({
    // ...
    jenkins: {
      serverAddress: 'http://localhost:8080',
      netrcMachine: 'ci',
      netrcLocation: '/tmp/.netrc'            // optional, default: '~/.netrc'
    }
  });
  grunt.loadNpmTasks('grunt-jenkins');
  // ...
};

Jenkins is authenticated and credentials are provided by username/password

module.exports = function(grunt) {
  grunt.initConfig({
    // ...
    jenkins: {
      serverAddress: 'http://localhost:8080',
      username: 'alf',                        // if only one of username and password
      password: 's3cret'                      // are provided, no authentication attempted
    }
  });
  grunt.loadNpmTasks('grunt-jenkins');
  // ...
};

Jenkins is running in a private cloud with a different than provided

If you needed the feature provided by PR #9, allowing job urls to be
overwritten by the given server url, this feature is opt-in as of v0.8.0. By
default we will use the PROVIDED url from the Jenkins api, which supports
different context roots.

module.exports = function(grunt) {
  grunt.initConfig({
    // ...
    jenkins: {
      serverAddress: 'http://localhost:8080',
      jobUrlResolutionStrategy: 'REWRITE_WITH_SERVER_ADDRESS'
    }
  });
  grunt.loadNpmTasks('grunt-jenkins');
  // ...
};

If a netrcMachine and username/password are provided, the netrc machine will be
used. If using username/password, please pass them in via a command line
argument instead of hardcoding in the build file.

If you are using Github OAuth for authentication, use API token instead of
password which you can find at <server-address>/user/<your-user-name>/configure.

Usage

grunt-jenkins makes it easier to evolve your
Jenkins installation. Jenkins configurations are often created
by many people over a long time. Making changes to Jenkins confidently without
the appropriate tools can be difficult.

Back up the configuration

Having configuration in source control gives us the confidence to make changes
and know that we can go back to a working state. To create a backup of all jobs
run grunt jenkins-backup-jobs. Behind the scenes, grunt-jenkins will:

  1. Create pipelineDirectory if necessary
  2. For each job: Create pipelineDirectory/jobName/config.xml

Verify the backup, constantly

Having our jobs in source control is great, but it can't make us completely
confident. Jenkins encourages users to change the configuration through the UI,
and that can leave our backed up version out of sync with the server.
grunt-jenkins makes it easy to verify the configuration in source control
matches exactly the version running on the server. Create a job as part of your
pipeline that runs grunt jenkins-verify-jobs to ensure the configuration is
the same as source control.

In The News

Release History

0.8.0 on 20-Nov-2016

0.7.1 on 7-Nov-2016

0.7.0 on 5-Nov-2016

0.6.0 on 17-Jan-2016

0.5.0 on 23-Jun-2014

0.4.0 on 5-Nov-2013

0.3.0 on 15-Sep-2013

0.2.0 on 14-Apr-2013

0.1.1 on 12-Nov-2012

0.1.0 on 11-Nov-2012, from the Alaskan skies!

jobs-related tasks

plugins-related tasks

convenience tasks

License

Copyright (c) 2012-2016 sghill
Licensed under the MIT license.