Manage Jenkins with Grunt
Manage Jenkins with Grunt
Install this grunt plugin next to your project's Gruntfile.js with:
$ npm install grunt-jenkins --save-dev
gruntinitConfig// ...jenkins:serverAddress: ''pipelineDirectory: 'jenkins-pipeline' // optional, default: 'pipeline';gruntloadNpmTasks'grunt-jenkins';// ...;
Jenkins is authenticated and credentials are in .netrc (preferred)
gruntinitConfig// ...jenkins:serverAddress: ''netrcMachine: 'ci'netrcLocation: '/tmp/.netrc' // optional, default: '~/.netrc';gruntloadNpmTasks'grunt-jenkins';// ...;
gruntinitConfig// ...jenkins:serverAddress: ''username: 'alf' // if only one of username and passwordpassword: 's3cret' // are provided, no authentication attempted;gruntloadNpmTasks'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.
grunt-jenkins is a tool that makes it easier to keep track of, and work on, your Jenkins installation. Jenkins configurations are often works of art, crafted by many people over a long period of time. Making changes confidently in such an environment without the appropriate tools can be daunting.
My preferred way of mitigating CI configuration risk is to check the configuration into source control. Having configuration in source control gives us the confidence to make changes and know that we can go back to a working state. Creating a backup of all of our jobs is fairly simple -- just run the
grunt jenkins-backup-jobs command. A pipeline directory will be created, a folder for each job within the pipeline directory, and the configuration will be saved to a
config.xml file within the job directory.
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 in an inconsistent state relative to what is on the server. To ensure confidence with every checkin, grunt-jenkins makes it easy to verify the configuration in source control matches exactly the version running on the server. Simply create a job as part of your pipeline that runs
grunt jenkins-verify-jobs to ensure we're all working off the same copy.
There are plenty of places to contribute! Hotspots of complexity are highlighted by codeclimate. Refactoring for testability is especially welcome.
Before submitting a pull request, please make sure the build passes by running:
$ npm test
- bugfix: authentication broken when no auth used #6
- badges: now built by travisci against node 0.8 and 0.10
- badges: dependencies are watched by david
- badges: codeclimate reports on complexity
- logging: log error when authentication fails #7
- logging: logs if and where authentication is coming from
- logging: much more information on requests and responses with --verbose
- compatibility with password-protected jenkins instances via .netrc or username/password. Thanks @panozzaj!
- compatibility with grunt 0.4.x
FileSystemclasses, as globally-installed grunt instances couldn't be
- list all jobs on a server with
- backup every job's config.xml to pipeline-directory/job-name/config.xml with
- verify each configuration in pipeline-directory/ matches the job configurations on the server with
- install jobs from pipeline-directory/ with
- list all enabled plugins and their versions with
- backup plugins to pipeline-directory/plugins.json with
- verify plugins in pipeline-directory/plugins.json match the plugins on the server with
- install plugins from pipeline-directory/plugins.json with
- for each of the tasks above, a shorter version exists that will run both:
Copyright (c) 2012 sghill Licensed under the MIT license.