Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
jenkins-api
Advanced tools
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');
If you need additional request parameters you can add them as explained in 'optional' section.
jenkins.build('job-in-jenkins', (optional){token: 'jenkins-token', ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.build_with_params('job-in-jenkins', (optional){depth: 1, <param>:<value>, token: 'jenkins-token',...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.stop_build('job-in-jenkins', 'build-number', (optional){token: 'jenkins-token', ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.console_output('job-in-jenkins', 'buildname', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
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)
});
jenkins.last_build_info('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.last_completed_build_info('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.all_builds('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.test_result('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_report('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
// if (err){ return console.log(err); }
// console.log(data)
// });
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)
});
jenkins.all_jobs((optional){token: 'jenkins-token', ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.get_config_xml('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.update_config('job-to-update'
,function(config) {
// function which takes the config.xml, and returns
// the new config xml for the new job
return config.replace('development','feature-branch');
}
,(optional){token: 'jenkins-token', ...}
,function(err, data) {
// if no error, job was copied
if (err){ return console.log(err); }
console.log(data)
});
jenkins.update_job('job-to-update', xmlConfigString, (optional){token: 'jenkins-token', ...}, function(err, data) {
// if no error, job was copied
if (err){ return console.log(err); }
console.log(data)
});
jenkins.job_info('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.create_job('job-in-jenkins', xmlConfigString, (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
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');
}
,(optional){token: 'jenkins-token', ...}
,function(err, data) {
// if no error, job was copied
if (err){ return console.log(err); }
console.log(data)
});
jenkins.delete_job('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.enable_job('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.disable_job('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.last_success('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.last_result('job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.queue((optional){token: 'jenkins-token', ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.queue_item('queue-item-number', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.cancel_item('queue-item-number', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.computers((optional){token: 'jenkins-token', ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.all_views((optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.create_view('new-view-name', (optional)viewMode = 'hudson.model.ListView', (optional){token: 'jenkins-token', ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.create_view('view-name', (optional){token: 'jenkins-token', ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
var viewConfig = {
name: "view-in-jenkins",
"description": "This is the view-in-jenkins View",
"statusFilter": "",
"job-in-jenkins": true,
"useincluderegex": true,
"includeRegex": "prefix.*",
"columns": [{"stapler-class": "hudson.views.StatusColumn", "$class": "hudson.views.StatusColumn"}, {"stapler-class": "hudson.views.WeatherColumn", "$class": "hudson.views.WeatherColumn"}, {"stapler-class": "hudson.views.JobColumn", "$class": "hudson.views.JobColumn"}, {"stapler-class": "hudson.views.LastSuccessColumn", "$class": "hudson.views.LastSuccessColumn"}, {"stapler-class": "hudson.views.LastFailureColumn", "$class": "hudson.views.LastFailureColumn"}, {"stapler-class": "hudson.views.LastDurationColumn", "$class": "hudson.views.LastDurationColumn"}, {"stapler-class": "hudson.views.BuildButtonColumn", "$class": "hudson.views.BuildButtonColumn"}]
};
jenkins.update_view('view-in-jenkins', viewConfig, (optional){token: 'jenkins-token', ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.delete_view('view-in-jenkins', (optional){token: 'jenkins-token', ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.add_job_to_view('view-in-jenkins', 'job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
jenkins.remove_job_from_view('view-in-jenkins', 'job-in-jenkins', (optional) {depth: 1, <param>:<value>, ...}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
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)
});
jenkins.all_installed_plugins((optional){token: 'jenkins-token', ...}, function(err, data){
if (err){ return console.log(err); }
console.log(data)
})
// var plugin = 'copyartifact@1.3.8';
var plugin = 'copyartifact@current';
jenkins.install_plugin(plugin, (optional){token: 'jenkins-token', ...}, function(err, data){
if (err){ return console.log(err, data); }
console.log(data)
});
NOTE: It will report successful even if the plugin is already installed. NOTE: Prevent Cross Site Request Forgery exploits need be disabled in Configure Global Security.
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.
Modeled after the Python Jenkins API
FAQs
Jenkins API written in Node.js
The npm package jenkins-api receives a total of 3,300 weekly downloads. As such, jenkins-api popularity was classified as popular.
We found that jenkins-api demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.