-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
138 additions
and
21 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var fs = require("fs"); | ||
var path = require('path'); | ||
var _ = require('underscore'); | ||
var authHelper = require("../util/auth"); | ||
|
||
/** | ||
* Stream jenkins logs | ||
*/ | ||
module.exports = (auth, jobName, queueNumber,writter, callback) => { | ||
var options = authHelper.createJenkinsOptions(auth.url, auth.user, auth.password); | ||
var jenkins = require('jenkins')(options); | ||
jenkins.queue.item(queueNumber, function (err, data) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
if (!data.executable || !data.executable.number) { | ||
return writter.log("Build did not started yet! Try again later"); | ||
} | ||
var buildNo = data.executable.number; | ||
|
||
const logStream = jenkins.build.logStream(jobName, buildNo); | ||
writter.log(`## Starting streaming build ${buildNo} log`); | ||
logStream.on('data', function (text) { | ||
writter.log(text); | ||
}); | ||
logStream.on('error', function (err) { | ||
writter.error(err); | ||
}); | ||
|
||
logStream.on('end', function () { | ||
writter.log('Build finished'.gray); | ||
callback(err, data); | ||
}); | ||
}); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var fs = require("fs"); | ||
var path = require('path'); | ||
var _ = require('underscore'); | ||
var authHelper = require("../util/auth"); | ||
|
||
/** | ||
* Trigger jenkins build | ||
*/ | ||
module.exports = (auth, jobName, callback) => { | ||
var options = authHelper.createJenkinsOptions(auth.url, auth.user, auth.password); | ||
var jenkins = require('jenkins')(options); | ||
jenkins.job.build(jobName, function (err, queueNumber) { | ||
callback(err, queueNumber); | ||
}); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Login into jenkins command | ||
var conf = require("../../util/config"); | ||
var logger = require("../../util/logger"); | ||
var prompt = require('readline-sync'); | ||
|
||
var triggerBuild = require("../../api/triggerBuild"); | ||
|
||
exports.command = 'build <job>' | ||
exports.describe = 'Trigger build for Jenkins job' | ||
exports.builder = (yargs) => { | ||
return yargs.count('verbose').alias('v', 'verbose'); | ||
} | ||
|
||
exports.handler = (argv) => { | ||
if (!argv.job) { | ||
argv.job = prompt.question('Jenkins job name: '); | ||
} | ||
triggerBuild(conf.get("auth"), argv.job, function (err, queueNumber) { | ||
if (err) { | ||
logger.error(`Problem when triggering new build for ${argv.job} job`); | ||
if (argv.v) { | ||
logger.error(err); | ||
} | ||
return; | ||
} | ||
logger.info(`Build for job ${argv.job} started! Use "log ${argv.job} ${queueNumber}" command to fetch logs`); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Login into jenkins command | ||
var conf = require("../util/config"); | ||
var logger = require("../util/logger"); | ||
var prompt = require('readline-sync'); | ||
|
||
var streamLogs = require("../api/streamLogs"); | ||
|
||
exports.command = 'log <job> <queueid>' | ||
exports.describe = 'Stream jenkins logs for triggered build' | ||
exports.builder = (yargs) => { | ||
return yargs.count('verbose').alias('v', 'verbose'); | ||
} | ||
|
||
exports.handler = (argv) => { | ||
if (!argv.job) { | ||
argv.job = prompt.question('Jenkins job name: '); | ||
} | ||
streamLogs(conf.get("auth"), argv.job, argv.queueid, console, function (err, data) { | ||
if (err) { | ||
logger.error(`Cannot fetch build log for ${argv.job}`); | ||
if (argv.verbose) { | ||
logger.error(err); | ||
} | ||
return; | ||
} | ||
}); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters