Skip to content
This repository was archived by the owner on Jan 23, 2020. It is now read-only.

Added case for non-successful, non-failed builds#140

Merged
nmuesch merged 4 commits into
DataDog:masterfrom
alanranciato:master
Feb 11, 2019
Merged

Added case for non-successful, non-failed builds#140
nmuesch merged 4 commits into
DataDog:masterfrom
alanranciato:master

Conversation

@alanranciato

Copy link
Copy Markdown
Contributor

Marking as warning rather than failure for build not successful, but not failed.

if ABORTED, UNSTABLE, or NOT_BUILT jenkins spec, set as status = warning and pass the correct build result in the title.

#139

Marking as warning rather than failure.
and that's what happens when you've been working in Groovy for too long.

Fixed string literals and lowercase method.

@nmuesch nmuesch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, thanks for this! @alanranciato I left a couple minor things. Some of them are unrelated to your direct changes, but would be great to include. Let me know if you'd like me to add those in a separate commit if you don't have the time.

} else if ("UNSTABLE".equals(builddata.get("result")) || "ABORTED".equals(builddata.get("result")) || "NOT_BUILT".equals(builddata.get("result"))) {
title.append(" " + builddata.get("result").toString().toLowerCase());
payload.put("alert_type", "warning");
message = "%%% \n [See results for build #" + number + "](" + buildurl + ") ";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move these outside of the conditionals, it looks like the message is the same throughout each of these.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Changes the message in the title slightly from failed ==> failure and succeeded ==> success. Alert type remains unchanged.

payload.put("alert_type", "success");
payload.put("priority", "low");
message = "%%% \n [See results for build #" + number + "](" + buildurl + ") ";
} else if ("UNSTABLE".equals(builddata.get("result")) || "ABORTED".equals(builddata.get("result")) || "NOT_BUILT".equals(builddata.get("result"))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we possibly setup an enum here for the different result types?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Utilizing Hudson.model.Result class for conditional.

payload.put("alert_type", "warning");
message = "%%% \n [See results for build #" + number + "](" + buildurl + ") ";
} else if (builddata.get("result") != null) {
title.append(" failed");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're here, we should probably catch this and only return failed if we are indeed in an error state - https://javadoc.jenkins-ci.org/hudson/model/Result.html.

We could fallback to some unknown instead of failed here in this default case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if null, setting to not_built state and warning. Only failure returns error.

String buildResult = builddata.get("result") != null ? builddata.get("result").toString() : Result.NOT_BUILT.toString() ;

1) broke title and message from conditional
2) utilize hudson.model.Result class vs. strings
3) set NULL result to NOT_BUILT vs. failure
Reorder the setting of the result
@alanranciato

Copy link
Copy Markdown
Contributor Author

@nmuesch - requested changes checked in and ready for review.

@nmuesch

nmuesch commented Feb 11, 2019

Copy link
Copy Markdown
Contributor

@alanranciato Thanks a lot for this! Looks 💯 I'll go ahead and merge.

@nmuesch nmuesch added this to the Next milestone Feb 11, 2019
@nmuesch
nmuesch merged commit 79de90e into DataDog:master Feb 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants