Example #1
0
 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(', ');
 });
Example #2
0
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);
};
Example #3
0
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);
}
Example #4
0
 function _success(result, cb) {
   if (result.headers['x-jenkins']) {
     cb(null, result.headers['x-jenkins']);
   } else {
     cb(new Error(text.__('Not a Jenkins server')));
   }
 }
Example #5
0
 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);
   });
 }
Example #6
0
 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);
   });
 }));
Example #7
0
 commander.prompt(text.__('Username: '******'Password: '******':' + pass;
     url = _url.format(parsedUrl);
     cb(new Jenkins(url));
   });
 });
Example #8
0
 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);
     });
   }
 }));
Example #9
0
 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);
     });        
   }
 }
Example #10
0
 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);
     });
   }
 }));
Example #11
0
 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);
     });
   }
 }
Example #12
0
 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'));
   }
 }));
Example #13
0
    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);
    }
Example #14
0
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));
  }
}
Example #15
0
    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!') : '');
            }
          });
        });

      }
    }
Example #16
0
 cli.exitCb(null, function (result) {
   console.log(text.__('Job %s was stopped successfully'), jobName);
 })
Example #17
0
 function _authRequire(result, cb) {
   cb(new Error(text.__('Jenkins requires authentication - set username and password in Jenkins URL')));
 }
Example #18
0
 setTimeout(function () {
   cb(new Error(text.__('Unable to find any Jenkins instance on %s', host)));
 }, TIMEOUT);
Example #19
0
 jenkins.version(cli.exitCb(null, function (result) {
   console.log(text.__('Jenkins ver. %s', result));
 }));
Example #20
0
 result[computer].executors.forEach(function (executor) {
   if (!executor.idle) {
     console.log('  - %s | %s%%s', executor.name, executor.progress, (executor.stuck) ? text.__(' stuck!') : '');
   }
 });
Example #21
0
 function _notFound(result, cb) {
     cb(new Error(text.__('No build could be found for job %s', name)));
 }
Example #22
0
 function _notFound(result, cb) {
   cb(new Error(text.__('Job %s does not exist', jobName)));
 }
Example #23
0
 function resultCb(result) {
   console.log(text.__('View %s was updated successfully'), name);
 }
Example #24
0
 return function (result, cb) {
   cb(new Error(text.__('Job %s requires build parameters', name)));
 };
Example #25
0
 function _paramsRequire(result, cb) {
   cb(new Error(text.__('Job %s requires build parameters', jobName)));
 }
Example #26
0
 return function (result, cb) {
   cb(new Error(text.__('Job %s build %d does not exist', name, buildNumber)));
 };
Example #27
0
 return function (result, cb) {
   cb(new Error(text.__('View %s does not exist', name)));
 };
Example #28
0
 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);
 }));
Example #29
0
 result.forEach(function (job) {
   var status = text.__(job.status),
     color = COLORS[job.status] || 'grey';
   console.log('%s - %s', status[color], job.name);
 });
Example #30
0
 function _authFail(result, cb) {
   cb(new Error(text.__('Authentication failed - incorrect username and/or password in Jenkins URL')));
 }