Skip to content

Real-Skill/node-jenkins-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nodejs-jenkins-api

Install

npm install jenkins-api

Usage

setup

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');

If you need additional request parameters you can add them as explained in 'optional' section.

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', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

enable job

jenkins.enable_job('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

disable job

jenkins.disable_job('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

build

jenkins.build('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

stop build

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

build with params

jenkins.build('job-in-jenkins', {key: 'value'}, (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

build info

jenkins.build_info('job-in-jenkins', 'build-number', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

last build info

jenkins.last_build_info('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

last build report

jenkins.last_build_report('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

get config xml

jenkins.get_config_xml('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

update job

jenkins.update_job('job-to-update',
                   function(config) {
                       // function which takes the config.xml, and returns
                       // the new config xml for the job
                       return config.replace('development,'feature-branch');
                   }
                   ,function(err, data) {
                       // if no error, job was copied
                       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(err, data) {
                      // if no error, job was copied
                      if (err){ return console.log(err); }
                      console.log(data)
                });

delete job

jenkins.delete_job('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

delete build data for job

jenkins.delete_build('job-in-jenkins', 'build-number', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

last success

jenkins.last_success('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

last result

jenkins.last_result('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

job output

jenkins.job_output('job-in-jenkins', 'buildname', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

get all queued items

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

get one queued item

jenkins.queue_item('queue-item-number', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
  if (err){ return console.log(err); }
  console.log(data)
});

get all jenkins computers (aka workers)

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

get all jobs in view

jenkins.all_jobs_in_view('view-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
      if (err){ return console.log(err); }
        console.log(data)
});

Default configuration

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});

Futhermore, you can set your remote job token for authentication:

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

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

Notes

Modeled after the Python Jenkins API

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published