Skip to content

Commit

Permalink
feat: Dismiss job cancelled in SD (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
dokimyj authored Jan 31, 2020
1 parent 26cd707 commit 030db92
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
25 changes: 16 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,24 @@ class JenkinsExecutor extends Executor {
params: [{ name: jobName }]
});

if (!(job && job.lastBuild && job.lastBuild.number)) {
throw new Error('No build has been started yet, try later');
if (!job) {
throw new Error('No jobs in process yet, try later');
}

await this.breaker.runCommand({
module: 'build',
action: 'stop',
params: [{ name: jobName, number: job.lastBuild.number }]
});

return this._jenkinsJobWaitStop(jobName, 0);
if (job.inQueue && job.queueItem && job.queueItem.id) {
await this.breaker.runCommand({
module: 'queue',
action: 'cancel',
params: [{ number: job.queueItem.id }]
});
} else if (job.lastBuild && job.lastBuild.number) {
await this.breaker.runCommand({
module: 'build',
action: 'stop',
params: [{ name: jobName, number: job.lastBuild.number }]
});
await this._jenkinsJobWaitStop(jobName, 0);
}
}

/**
Expand Down
10 changes: 3 additions & 7 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,18 +428,14 @@ describe('index', () => {
});
});

it('return error when there is no build to be stopped yet', done => {
const noBuildJobInfo = {
lastBuild: null
};

breakerMock.runCommand.withArgs(getOpts).resolves(noBuildJobInfo);
it('return error when there are no jobs in process yet', done => {
breakerMock.runCommand.withArgs(getOpts).resolves(null);
breakerMock.runCommand.withArgs(stopOpts).resolves(null);

executor.stop({ buildId: config.buildId }).catch(err => {
assert.deepEqual(
err.message,
'No build has been started yet, try later'
'No jobs in process yet, try later'
);
done();
});
Expand Down

0 comments on commit 030db92

Please sign in to comment.