Skip to content

Commit

Permalink
fixed error being ignored on build and are now handling
Browse files Browse the repository at this point in the history
getBuildNumber as a promise. Logs no longer fails if get build number takes too long to respond.
  • Loading branch information
patrick-motard committed Aug 15, 2018
1 parent 8ef9b97 commit 89b2c0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ var Promise = require('bluebird'),
require('dotenv-safe').config({
path: `${process.cwd()}/.env`,
example: `${__dirname}/.env.example`
})
});

var Pipeline = function({ user, token, url, jobName, parameters={} }) {
function crash(e) {
console.log(e);
return process.exit(1);
}

var Pipeline = function({ user, token, url, jobName, parameters }) {
this.url = `https://${user}:${token}@${url}/`;
this.jenkins = require('jenkins')({
baseUrl: this.url,
Expand All @@ -24,14 +29,14 @@ var Pipeline = function({ user, token, url, jobName, parameters={} }) {

Pipeline.prototype.getLatestBuildNumber = function() {
return this.jenkins.job.get(this.options)
.then(res => {
this.options.number = res.lastBuild.number;
});
.then(res => this.options.number = res.lastBuild.number)
.catch(crash);
}

Pipeline.prototype.build = function() {
return this.jenkins.job.build(this.options)
.then(() => this.getLatestBuildNumber());
.then(() => this.getLatestBuildNumber())
.catch(crash)
}

Pipeline.prototype.stop = function() {
Expand Down Expand Up @@ -62,7 +67,6 @@ Pipeline.prototype.log = function() {
if (done) return Promise.resolve();
setTimeout(resolver, 30);
})();

}

function parseParams(params) {
Expand Down Expand Up @@ -117,4 +121,3 @@ module.exports = () => {

module.exports();


2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jenky",
"version": "1.1.0",
"version": "1.1.1",
"description": "Call your jenkins pipelines from the command line.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 89b2c0e

Please sign in to comment.