jenkins-api

Jenkins API written in Node.js

nodejs-jenkins-api

npm install jenkins-api
var jenkinsapi = require('jenkins-api');
 
// no auth 
var jenkins = jenkinsapi.init("http://jenkins.yoursite.com");
 
// username/password 
var jenkins = jenkinsapi.init("http://username:password@jenkins.yoursite.com");
 
// API Token 
var jenkins = jenkinsapi.init('https://username:token@jenkins.company.com');
 
jenkins.all_jobs(function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.job_info('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.enable_job('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.disable_job('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.build('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.build('job-in-jenkins', {key: 'value'}, function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.build_info('job-in-jenkins', 'build-number', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.last_build_info('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.last_build_report('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.get_config_xml('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.copy_job('job-to-copy'
                ,'new-job-title'
                ,function(config) {
                    // function which takes the config.xml, and returns 
                    // the new config xml for the new job 
                    return config.replace('development','feature-branch');
                }
                ,function(errdata) {
                      // if no error, job was copied 
                      if (err){ return console.log(err); }
                      console.log(data)
                });
jenkins.delete_job('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.last_success('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.last_result('job-in-jenkins', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.job_output('job-in-jenkins', 'buildname', function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.queue(function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});
jenkins.computers(function(errdata) {
  if (err){ return console.log(err); }
  console.log(data)
});

You can set the default configuration which will be use in all HTTP requests by calling init with the additional options parameter:

// default request options 
var jenkins = jenkinsapi.init("http://jenkins.yoursite.com", {strictSSL: false});

Since node-jenkins-api uses request/request as HTTP client, please refer to the documentation for available options.

Modeled after the Python Jenkins API