computers.forEach(function (computer) { data[computer.displayName] = { executors: [] }; var idleCount = 0, activeCount = 0; computer.executors.forEach(function (executor) { data[computer.displayName].executors.push({ idle: executor.idle, stuck: executor.likelyStuck, progress: executor.progress, name: (!executor.idle) ? executor.currentExecutable.url.replace(/.*\/job\//, '').replace(/\/.*/, '') : undefined }); if (executor.idle) { idleCount += 1; } else { activeCount += 1; } }); var summary = []; if (activeCount > 0) { summary.push(text.__('%d active', activeCount)); } if (idleCount > 0) { summary.push(text.__('%d idle', idleCount)); } data[computer.displayName].summary = summary.join(', '); });
Jenkins.prototype.discover = function (host, cb) { const TIMEOUT = 5000; var socket = dgram.createSocket('udp4'), buffer = new Buffer(text.__('Long live Jenkins!')), parser = new xml2js.Parser(); socket.on('error', function (err) { socket.close(); cb(err); }); socket.on('message', function (result) { socket.close(); parser.addListener('end', function (result) { cb(null, result); }); parser.parseString(result); }); socket.send(buffer, 0, buffer.length, 33848, host, function (err, result) { if (err) { socket.close(); cb(err); } }); setTimeout(function () { cb(new Error(text.__('Unable to find any Jenkins instance on %s', host))); }, TIMEOUT); };
function _build(jobName, params, args) { if (!args) { args = params || {}; } const PENDING = 5000; var message = text.__('Job %s was started successfully'), cb; if (args.console) { cb = function (err, result) { if (err) { cli.exit(err, result); } else { console.log(message, jobName); // wait for pending period before calling console setTimeout(function () { _console(jobName); }, args.pending || PENDING); } }; } else { cb = cli.exitCb(null, function (result) { console.log(message, jobName); }); } function execCb(jenkins) { jenkins.build(jobName, (_.isString(params)) ? params : undefined, cb); } __exec(args, execCb); }
function _success(result, cb) { if (result.headers['x-jenkins']) { cb(null, result.headers['x-jenkins']); } else { cb(new Error(text.__('Not a Jenkins server'))); } }
function resultCb(result) { var status = util.statusByColor(result.color); var color = util.colorByStatus(status, result.color); console.log('%s | %s', name, text.__(status)[color]); result.healthReport.forEach(function (report) { console.log(' - %s', report.description); }); }
jenkins.job(name, cli.exitCb(null, function (result) { var status = text.__(result.status), color = [COLORS[result.status] || 'grey']; console.log('%s | %s', name, status[color]); result.reports.forEach(function (report) { console.log(' - %s', report); }); }));
commander.prompt(text.__('Username: '******'Password: '******':' + pass; url = _url.format(parsedUrl); cb(new Jenkins(url)); }); });
jenkins.queue(cli.exitCb(null, function (result) { if (result.length === 0) { console.log(text.__('Queue is empty')); } else { result.forEach(function (job) { console.log('- %s', job); }); } }));
function resultCb(result) { var items = JSON.parse(result).items; if (_.isEmpty(items)) { console.log(text.__('Queue is empty')); } else { items.forEach(function (item) { console.log('- %s', item.task.name); }); } }
jenkins.dashboard(cli.exitCb(null, function (result) { if (result.length === 0) { console.log(text.__('Jobless Jenkins')); } else { result.forEach(function (job) { var status = text.__(job.status), color = COLORS[job.status] || 'grey'; console.log('%s - %s', status[color], job.name); }); } }));
function resultCb(result) { var jobs = result.jobs; if (_.isEmpty(jobs)) { console.log(text.__('Jobless Jenkins')); } else { jobs.forEach(function (job) { var status = util.statusByColor(job.color); var color = util.colorByStatus(status, job.color); console.log('%s - %s', text.__(status)[color], job.name); }); } }
jenkins.executor(cli.exitCb(null, function (result) { if (!_.isEmpty(_.keys(result))) { _.keys(result).forEach(function (computer) { console.log('+ %s | %s', computer, result[computer].summary); result[computer].executors.forEach(function (executor) { if (!executor.idle) { console.log(' - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? text.__(' stuck!') : ''); } }); }); } else { console.log(text.__('No executor found')); } }));
function resultCb(result) { var status; var color; var description; if (result.building) { status = 'building'; color = util.colorByStatus(status); description = _util.format('Started %s', moment(result.timestamp).fromNow()); } else { status = result.result.toLowerCase(); color = util.colorByStatus(status); description = _util.format('Finished %s', moment(result.timestamp + result.duration).fromNow()); } console.log('%s | %s', name, text.__(status)[color]); console.log(' - %s', description); }
function __exec(args, cb) { // use url flag or JENKINS_URL environment variable if provided var url = (args && args.parent) ? (args.parent.url || process.env.JENKINS_URL) : undefined; // if URL value and interactive flag are specified, then prompt for authentication details if (url && args.parent && args.parent.interactive) { commander.prompt(text.__('Username: '******'Password: '******':' + pass; url = _url.format(parsedUrl); cb(new Jenkins(url)); }); }); // otherwise fallback to default URL } else { cb(new Jenkins(url)); } }
function resultCb(result) { var computers = result.computer; if (_.isEmpty(computers)) { console.log(text.__('No executor found')); } else { var data = Jenkins.executorSummary(computers); _.keys(data).forEach(function (computer) { console.log('+ %s | %s', computer, data[computer].summary); data[computer].executors.forEach(function (executor) { if (!executor.idle) { console.log(' - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? text.__(' stuck!') : ''); } }); }); } }
cli.exitCb(null, function (result) { console.log(text.__('Job %s was stopped successfully'), jobName); })
function _authRequire(result, cb) { cb(new Error(text.__('Jenkins requires authentication - set username and password in Jenkins URL'))); }
setTimeout(function () { cb(new Error(text.__('Unable to find any Jenkins instance on %s', host))); }, TIMEOUT);
jenkins.version(cli.exitCb(null, function (result) { console.log(text.__('Jenkins ver. %s', result)); }));
result[computer].executors.forEach(function (executor) { if (!executor.idle) { console.log(' - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? text.__(' stuck!') : ''); } });
function _notFound(result, cb) { cb(new Error(text.__('No build could be found for job %s', name))); }
function _notFound(result, cb) { cb(new Error(text.__('Job %s does not exist', jobName))); }
function resultCb(result) { console.log(text.__('View %s was updated successfully'), name); }
return function (result, cb) { cb(new Error(text.__('Job %s requires build parameters', name))); };
function _paramsRequire(result, cb) { cb(new Error(text.__('Job %s requires build parameters', jobName))); }
return function (result, cb) { cb(new Error(text.__('Job %s build %d does not exist', name, buildNumber))); };
return function (result, cb) { cb(new Error(text.__('View %s does not exist', name))); };
jenkins.discover(host, cli.exitCb(null, function (result) { console.log(text.__('Jenkins ver. %s is running on %s'), result.hudson.version[0], (result.hudson.url && result.hudson.url[0]) ? result.hudson.url[0] : host); }));
result.forEach(function (job) { var status = text.__(job.status), color = COLORS[job.status] || 'grey'; console.log('%s - %s', status[color], job.name); });
function _authFail(result, cb) { cb(new Error(text.__('Authentication failed - incorrect username and/or password in Jenkins URL'))); }