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

New job option:Mention Everyone For Failure. #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public void completed(AbstractBuild r) {
|| (result == Result.UNSTABLE && jobProperty.getNotifyUnstable())) {
getHipChat(r).publish(getBuildStatusMessage(r), getBuildColor(r));
}

if ((result == Result.FAILURE || result == Result.UNSTABLE) && jobProperty.getMentionAll()) {
getHipChat(r).publish("@all " + r.getProject().getDisplayName() + " failed. Fix it ASAP!!! Stop pushing until it comes back to normal!!!.", "red", "text");
}
}

String getChanges(AbstractBuild r) {
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public static class HipChatJobProperty extends hudson.model.JobProperty<Abstract
private boolean notifyUnstable;
private boolean notifyFailure;
private boolean notifyBackToNormal;
private boolean mentionAll;


@DataBoundConstructor
Expand All @@ -154,7 +155,8 @@ public HipChatJobProperty(String room,
boolean notifyNotBuilt,
boolean notifySuccess,
boolean notifyUnstable,
boolean notifyBackToNormal) {
boolean notifyBackToNormal,
boolean mentionAll) {
this.room = room;
this.startNotification = startNotification;
this.notifyAborted = notifyAborted;
Expand All @@ -163,6 +165,7 @@ public HipChatJobProperty(String room,
this.notifySuccess = notifySuccess;
this.notifyUnstable = notifyUnstable;
this.notifyBackToNormal = notifyBackToNormal;
this.mentionAll = mentionAll;
}

@Exported
Expand Down Expand Up @@ -219,6 +222,11 @@ public boolean getNotifyBackToNormal() {
return notifyBackToNormal;
}

@Exported
public boolean getMentionAll() {
return mentionAll;
}

@Extension
public static final class DescriptorImpl extends JobPropertyDescriptor {
public String getDisplayName() {
Expand All @@ -239,7 +247,8 @@ public HipChatJobProperty newInstance(StaplerRequest sr, JSONObject formData) th
sr.getParameter("hipChatNotifyNotBuilt") != null,
sr.getParameter("hipChatNotifySuccess") != null,
sr.getParameter("hipChatNotifyUnstable") != null,
sr.getParameter("hipChatNotifyBackToNormal") != null);
sr.getParameter("hipChatNotifyBackToNormal") != null,
sr.getParameter("hipChatMentionAll") != null);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jenkins/plugins/hipchat/HipChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public interface HipChatService {
void publish(String message);

void publish(String message, String color);

void publish(String message, String color, String message_format);
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public void publish(String message) {
}

public void publish(String message, String color) {
publish(message,color,"html");
}

public void publish(String message, String color, String message_format) {
for (String roomId : roomIds) {
logger.info("Posting: " + from + " to " + roomId + ": " + message + " " + color);
HttpClient client = getHttpClient();
Expand All @@ -43,6 +47,7 @@ public void publish(String message, String color) {
post.addParameter("message", message);
post.addParameter("color", color);
post.addParameter("notify", shouldNotify(color));
post.addParameter("message_format",message_format);
post.getParams().setContentCharset("UTF-8");
int responseCode = client.executeMethod(post);
String response = post.getResponseBodyAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<f:checkbox name="hipChatNotifyBackToNormal" value="true" checked="${instance.getNotifyBackToNormal()}"/>
</f:entry>

<f:entry title="Mention Everyone For Failure">
<f:checkbox name="hipChatMentionAll" value="true" checked="${instance.getMentionAll()}"/>
</f:entry>

</f:section>

</j:jelly>