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';// ...;
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
FileSystemclasses, as globally-installed grunt instances couldn't be
Copyright (c) 2012 sghill Licensed under the MIT license.