Coder Social home page Coder Social logo

grunt-jenkins's Introduction

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

  • Support alternate context roots with default jobUrlResolutionStrategy #13
  • If you need the support provided by #9 for using the given server address instead of the job url provided by the Jenkins API, this is now opt-in by setting jobUrlResolutionStrategy to 'REWRITE_WITH_SERVER_ADDRESS'
  • Upgrade request dependency to 2.79.0

0.7.1 on 7-Nov-2016

  • Whitelist files for package to exclude unnecessary files from installation

0.7.0 on 5-Nov-2016

  • upgrade dependencies
  • test against node 4, 5, 6, 7
  • require >= node 4.0.0

0.6.0 on 17-Jan-2016

  • feature: handle periods in job names #11. Thanks @dtJuiceMobile!
  • badges: npm version badge added
  • badges: now built by travisci against node 0.10, 0.12, 4.0, and 4.1
  • docs: readme update for using with github oauth #10. Thanks @floydpraveen!

0.5.0 on 23-Jun-2014

  • feature: support Jenkins running on NAT network in private cloud #9. Thanks @StefanScherer!

0.4.0 on 5-Nov-2013

  • 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

0.3.0 on 15-Sep-2013

  • compatibility with password-protected jenkins instances via .netrc or username/password. Thanks @panozzaj!

0.2.0 on 14-Apr-2013

  • compatibility with grunt 0.4.x

0.1.1 on 12-Nov-2012

  • inject grunt instance into JenkinsServer and FileSystem classes, as globally-installed grunt instances couldn't be required

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

jobs-related tasks

  • list all jobs on a server with jenkins-list-jobs
  • backup every job's config.xml to pipelineDirectory/jobName/config.xml with jenkins-backup-jobs
  • verify each configuration in pipelineDirectory/ matches the job configurations on the server with jenkins-verify-jobs
  • install jobs from pipelineDirectory/ with jenkins-install-jobs

plugins-related tasks

  • list all enabled plugins and their versions with jenkins-list-plugins
  • backup plugins to pipelineDirectory/plugins.json with jenkins-backup-plugins
  • verify plugins in pipelineDirectory/plugins.json match the plugins on the server with jenkins-verify-plugins
  • install plugins from pipelineDirectory/plugins.json with jenkins-install-plugins

convenience tasks

  • for each of the tasks above, a shorter version exists that will run both: jenkins-list will run jenkins-list-jobs and jenkins-list-plugins

License

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

grunt-jenkins's People

Contributors

ds-steve avatar dtfreckle avatar panozzaj avatar sghill avatar stefanscherer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

grunt-jenkins's Issues

Cannot find module `grunt` when grunt installed globally

Loading "fileSystem.js" tasks and helpers...ERROR
>> Error: Cannot find module 'grunt'
Loading "jenkins.js" tasks and helpers...ERROR
>> Error: Cannot find module 'grunt'
Loading "jenkinsServer.js" tasks and helpers...ERROR
>> Error: Cannot find module 'grunt'

appears if grunt is not installed locally to the project.

Friendly error message when there is no pipeline directory present

Given I have not created the pipeline directory
When I attempt to verify/install jobs/plugins
Then I should see a friendly error message saying I need to create the pipeline directory or backup first

If you happen to run a verify task before backing up, which doesn't make a lot of sense anyway, it presents a somewhat confusing message:

Running "jenkins-verify-jobs" task
Found 1 jobs.
>> Error: ENOENT, readdir 'pipeline'

Error installing grunt-jenkins

Good afternoon,

I'm experiencing the following issue when trying to install grunt-jenkins:

install grunt-jenkins --save-dev
[               ...] - extract:hawk: verb gentlyRm don't care about contents; nuking D:\jenkinsbackupjobs\node_modules\.staging\hawk-aa7b66d5\node_modules

After this nothing happens (I waited more than 30 minutes) and the CPU usage is very high during this time.

I encounter similar issues with different nodejs/npm versions (like nodejs7/npm 3.10.8, nodejs6/npm 3.10.4 nodejs4/npm 2.14.4)

Do you know what can be the cause of this? Thank you very much in advance.

package.json:

{
  "name": "jenkinsbackupjobs",
  "version": "1.0.0",
  "description": "Jenkins Backup Jobs",
  "main": "Gruntfile.js",
  "devDependencies": {
    
  }
}

Gruntfile.js:

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

Issue when Jenkins installed in a non-root URL

Good afternoon,

I'm trying to use your plugin to get a backup of the Jenkins jobs in my installation. However, I'm facing an issue because my Jenkins is installed in http://localhost:8080/jenkins/ (and not on http://localhost:8080).

What happens is that it retrieves all the jobs correctly, but when trying to retrieve each job individually it constructs the URLs like this:
http://localhost:8080/jenkins//jenkins/job/Test-A-Config/config.xml

instead of
http://localhost:8080/jenkins/job/Test-A-Config/config.xml

I've seen how to fix it:
In jenkinsServer.js, line 50 I've replaced this

var path = j.url.replace(/^https?\:\/{2}[^\/]+\/(.*)/, '$1');
var url = [serverUrl, path].join('/');

with:

var path = j.url.replace(/^https?\:\/{2}[^\/]+\/(.*)/, '$1');
var serverHost = serverUrl.replace(/^(https?\:\/{2}[^\/]+)\/(.*)/, '$1');
var url = [serverHost, path].join('/');

Would it be possible for you to add this fix (or a similar one of your liking) to your published code? Because I have it running locally with the fix I mentioned above, but I'm planning to use it from the Jenkins server itself in which I don't have access to modify the jenkinsServer.js.

Thank you!

Best regards,
Emilio

Grunt 0.4 Release

I'm posting this issue to let you know that we will be publishing Grunt 0.4 on Monday, February 18th.

If your plugin is not already Grunt 0.4 compatible, would you please consider updating it? For an overview of what's changed, please see our migration guide.

If you'd like to develop against the final version of Grunt before Monday, please specify "grunt": "0.4.0rc8" as a devDependency in your project. After Monday's release, you'll be able to use "grunt": "~0.4.0" to actually publish your plugin. If you depend on any plugins from the grunt-contrib series, please see our list of release candidates for compatible versions. All of these will be updated to final status when Grunt 0.4 is published.

Also, in an effort to reduce duplication of effort and fragmentation in the developer community, could you review the grunt-contrib series of plugins to see if any of your functionality overlaps significantly with them? Grunt-contrib is community maintained with 40+ contributors—we'd love to discuss any additions you'd like to make.

Finally, we're working on a new task format that doesn't depend on Grunt: it's called node-task. Once this is complete, there will be one more conversion, and then we'll never ask you to upgrade your plugins to support our changes again. Until that happens, thanks for bearing with us!

If you have any questions about how to proceed, please respond here, or join us in #grunt on irc.freenode.net.

Thanks, we really appreciate your work!

TypeError: Cannot call method 'writeln' of undefined on grunt.log.writeln

I'm running into an issue running any of the grunt-jenkins tasks, for some reason it seems to have an undefined grunt.log and cannot call grunt.log.writeln().

grunt jenkins-list

Running "jenkins-list-jobs" task

/Users/ddaniels/Dropbox/code/github/projects/product/node_modules/grunt-jenkins/tasks/jenkinsServer.js:14
      grunt.log.writeln(['Found', jobs.length, 'jobs.'].join(' '));
                ^
TypeError: Cannot call method 'writeln' of undefined
    at Request.fetchJobs (/Users/ddaniels/Dropbox/code/github/projects/product/node_modules/grunt-jenkins/tasks/jenkinsServer.js:14:17)
    at Request.init.self.callback (/Users/ddaniels/Dropbox/code/github/projects/product/node_modules/grunt-jenkins/node_modules/request/main.js:122:22)
    at Request.EventEmitter.emit (events.js:99:17)
    at Request.<anonymous> (/Users/ddaniels/Dropbox/code/github/projects/product/node_modules/grunt-jenkins/node_modules/request/main.js:655:16)
    at Request.EventEmitter.emit (events.js:126:20)
    at IncomingMessage.Request.start.self.req.self.httpModule.request.buffer (/Users/ddaniels/Dropbox/code/github/projects/product/node_modules/grunt-jenkins/node_modules/request/main.js:617:14)
    at IncomingMessage.EventEmitter.emit (events.js:126:20)
    at IncomingMessage._emitEnd (http.js:366:10)
    at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)
    at Socket.socketOnData [as ondata] (http.js:1367:20)

jenkins-install-jobs doesn't appear to be working

Howdy,

I've run through the instructions in the README and I'm unable to get either changes to existing jobs or new jobs to install properly.

I have an almost completely vanilla setup:

Jenkins (ver. 1.537) running on localhost
node v0.10.21
grunt-cli v0.1.9
grunt v0.4.1

The job is embarrassingly simple:

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description></description>
  <logRotator class="hudson.tasks.LogRotator">
    <daysToKeep>-1</daysToKeep>
    <numToKeep>7</numToKeep>
    <artifactDaysToKeep>-1</artifactDaysToKeep>
    <artifactNumToKeep>-1</artifactNumToKeep>
  </logRotator>
  <keepDependencies>false</keepDependencies>
  <properties/>
  <scm class="hudson.scm.NullSCM"/>
  <canRoam>true</canRoam>
  <disabled>false</disabled>
  <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
  <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
  <triggers/>
  <concurrentBuild>false</concurrentBuild>
  <builders>
    <hudson.tasks.Shell>
      <command>echo &apos;Howdy&apos;</command>
    </hudson.tasks.Shell>
  </builders>
  <publishers/>
  <buildWrappers/>
</project>

Hand editing the command and numToKeep values, the verify command shows a difference (as expected), but running install does not update jenkins.

Any suggestions to help debug what's going wrong here?

Friendly error message when Jenkins requires auth

Given my jenkins requires authentication
When I attempt to install/verify/backup a job without authentication
Then I should see a friendly error message saying I need to be authenticated

Currently --

Running "jenkins-verify-jobs" task
Fatal error: Unexpected token <

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.