Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Jenkins API for NodeJS
JavaScript
Tree: 983a23bf62

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
README.md
package.json
testjenkinsapi.js

README.md

nodejs-jenkins-api

We needed a middleman server, and I decided to go with Node.js, but I found that there was no decent Node.js API. SO, I made one =). I was really impressed by the autojenkins python API, which it follows closely:

https://github.com/txels/autojenkins

There are many things you can do, such as:

Install

git clone git@github.com:jansepar/node-jenkins-api.git
cd node-jenkins-api
npm link

Usage

setup

var jenkinsapi = require('./jenkinsapi');

var jenkins = jenkinsapi.init("http://jenkins.yoursite.com");
// or with auth
var jenkins = jenkinsapi.init("http://username:password@jenkins.yoursite.com");

all jobs

jenkins.all_jobs(function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

job info

jenkins.job_info('job-in-jenkins', function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

last build info

jenkins.last_build_info('job-in-jenkins', function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

last build report

jenkins.last_build_report('job-in-jenkins', function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

get config xml

jenkins.get_config_xml('job-in-jenkins', function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

copy job

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(error, data) {
                      // if no error, job was copied
                      if (err){ return console.log(err); }
                      console.log(data)
                });

delete job

jenkins.delete_job('job-in-jenkins', function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

last success

jenkins.last_success('job-in-jenkins', function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

last result

jenkins.last_result('job-in-jenkins', function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});
Something went wrong with that request. Please try again.