Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reliably check whether a build has failed? #106

Open
markcellus opened this issue Dec 17, 2021 · 1 comment
Open

How to reliably check whether a build has failed? #106

markcellus opened this issue Dec 17, 2021 · 1 comment

Comments

@markcellus
Copy link

markcellus commented Dec 17, 2021

This is more of a question rather than an "issue". But let's say I'm using the following to retrieve a job object from a build that has failed:

const job = await jenkins.build.get('example', 123);

I tried using the following....

if (job.lastFailedBuild && job.lastFailedBuild.number === 123) {
  throw new Error('Build failed.');
}

But that doesn't work if some other build (567) has failed before the code above ☝️ runs.

Given this scenario, what is the recommended way to detect the build failure and throw an error?

@markcellus markcellus changed the title How to check whether a build has failed? How to reliably check whether a build has failed? Dec 17, 2021
@markcellus
Copy link
Author

markcellus commented Dec 18, 2021

Think I've found a way. Looks like I was incorrectly assuming that what was returned from build.get() was the job (per code snippet in #102 (comment), which has it assigned to a job const. I think assigning to a build const is more accurate. Then we can read from the result of the build.

const build = await jenkins.build.get('example', 123);
// ... build finishes
if (build.result === 'FAILURE') {
  throw new Error('Build failed.');
}

@silas do you mind confirming that my assumptions here are correct? If so, we can close ticket. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant