Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 4x 4x 2x 2x 2x 2x 2x 2x 2x 4x 2x 2x 2x 2x 2x 2x 4x 4x 1x 1x 1x 1x 1x 1x 1x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 2x 2x 2x 2x 2x 2x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | "use strict"; import _ from 'lodash'; import cli from 'bagofcli'; import fs from 'fs'; import moment from 'moment'; import util from './util.js'; import _util from 'util'; /** * Get a handler that calls Jenkins API to create a job with specific configuration. * Success job creation message will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function create(cb) { return function (command, args) { const name = _.get(args, '[0]'); const configFile = _.get(args, '[1]'); function resultCb(result) { console.log(`Job ${name} was created successfully`); } function jenkinsCb(jenkins) { const config = fs.readFileSync(configFile).toString(); jenkins.createJob(name, config, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to retrieve information about a job. * Job status and health reports will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function read(cb) { return function (command, args) { const name = _.get(args, '[0]'); function resultCb(result) { const status = util.statusByColor(result.color); const color = util.colorByStatus(status, result.color); console.log(`${name} | ${status[color]}`); result.healthReport.forEach(function (report) { console.log(' - %s', report.description); }); } function jenkinsCb(jenkins) { jenkins.readJob(name, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to retrieve information about the latest build of a job. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function readLatest(cb) { return function (command, args) { const name = _.get(args, '[0]'); function resultCb(result) { let status; let color; let 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(`${name} | ${status[color]}`); console.log(` - ${description}`); } function jenkinsCb(jenkins) { jenkins.readLatestJob(name, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to update a job with specific configuration. * Success job update message will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function update(cb) { return function (command, args) { const name = _.get(args, '[0]'); const configFile = _.get(args, '[1]'); function resultCb(result) { console.log(`Job ${name} was updated successfully`); } function jenkinsCb(jenkins) { const config = fs.readFileSync(configFile).toString(); jenkins.updateJob(name, config, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to delete a job. * Success job deletion message will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function _delete(cb) { return function (command, args) { const name = _.get(args, '[0]'); function resultCb(result) { console.log(`Job ${name} was deleted successfully`); } function jenkinsCb(jenkins) { jenkins.deleteJob(name, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to build a job. * Success job stopped message will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function build(cb) { // params arg is a query string like param1=value1¶m2=value2 return function (command, args) { const name = _.get(args, '[0]'); let paramsString = _.get(args, '[1]'); if (!command) { command = paramsString; paramsString = null; } function resultCb(result) { console.log(`Job ${name} was triggered successfully`); } function jenkinsCb(jenkins) { // simply pass jenkins instance to the next callback function passThroughCb(command, jenkinsCb) { jenkinsCb(jenkins); } const params = {}; if (paramsString) { paramsString.split('&').forEach(function (paramString) { const delim = paramString.indexOf('='); const key = paramString.substring(0, delim); const value = paramString.substring(delim + 1, paramString.length); params[key] = value; }); } const jenkinsPollIntervalMillis = 2000; const jenkinsPollRetries = command.poll || 15; function streamIfReady(buildUrl, ready, retries) { if (ready) { _console(passThroughCb)(name, null, command); } else { if (retries > 0) { console.log('Waiting for job to start...'); setTimeout(function () { jenkins.checkBuildStarted(buildUrl, function (ready) { streamIfReady(buildUrl, ready, retries - 1); }); }, jenkinsPollIntervalMillis); } else { const waitTime = (jenkinsPollIntervalMillis * jenkinsPollRetries) / 1000; console.log(`Build didn't start after ${waitTime} seconds, it's still waiting in the queue`); cli.exit({}, null); } } } let cb; // with console enabled, display result and poll until the job starts, then stream console output if (command.console) { cb = function (err, result, response) { resultCb(response); const buildUrl = response.headers.location; setTimeout(function () { jenkins.checkBuildStarted(buildUrl, function (ready) { streamIfReady(buildUrl, ready, jenkinsPollRetries); }); }, jenkinsPollIntervalMillis); }; // with console disabled, display result } else { cb = cli.exitCb(null, resultCb); } jenkins.buildJob(name, params, cb); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to stop a job. * Success job stopped message will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function stop(cb) { return function (command, args) { const name = _.get(args, '[0]'); function resultCb(result) { console.log(`Job ${name} was stopped successfully`); } function jenkinsCb(jenkins) { jenkins.stopJob(name, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to stream console output. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function _console(cb) { return function (command, args) { const name = _.get(args, '[0]'); let buildNumber = _.get(args, '[1]'); if (!command) { command = buildNumber; buildNumber = null; } function jenkinsCb(jenkins) { // console does not trigger any build, interval is set to 0 (no-pending delay time) const interval = 0; const stream = jenkins.streamJobConsole(name, buildNumber, interval, cli.exit); stream.pipe(process.stdout, { end: false }); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to enable a job. * Success job enabled message will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function enable(cb) { return function (command, args) { const name = _.get(args, '[0]'); function resultCb(result) { console.log(`Job ${name} was enabled successfully`); } function jenkinsCb(jenkins) { jenkins.enableJob(name, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to disable a job. * Success job disabled message will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function disable(cb) { return function (command, args) { const name = _.get(args, '[0]'); function resultCb(result) { console.log(`Job ${name} was disabled successfully`); } function jenkinsCb(jenkins) { jenkins.disableJob(name, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to copy a job into a new job. * Success job copy message will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function copy(cb) { return function (command, args) { const existingName = _.get(args, '[0]'); const newName = _.get(args, '[1]'); function resultCb(result) { console.log(`Job ${existingName} was copied to job ${newName}`); } function jenkinsCb(jenkins) { jenkins.copyJob(existingName, newName, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } /** * Get a handler that calls Jenkins API to fetch a job configuration. * Jenkins job config.xml will be logged when there's no error. * * @param {Function} cb: callback for argument handling * @return Jenkins API handler function */ function fetchConfig(cb) { return function (command, args) { const name = _.get(args, '[0]'); function resultCb(result) { console.log(result); } function jenkinsCb(jenkins) { jenkins.fetchJobConfig(name, cli.exitCb(null, resultCb)); } cb(command, jenkinsCb); }; } const exports = { create: create, read: read, readLatest: readLatest, update: update, delete: _delete, build: build, stop: stop, console: _console, enable: enable, disable: disable, copy: copy, fetchConfig: fetchConfig }; export { exports as default }; |