Skip to content

Commit

Permalink
Fix JENKINS-22154 - Add disable at project level
Browse files Browse the repository at this point in the history
  • Loading branch information
slide committed Jul 11, 2014
1 parent e542f6e commit aedbab2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/main/java/hudson/plugins/emailext/ExtendedEmailPublisher.java
Expand Up @@ -146,13 +146,18 @@ public class ExtendedEmailPublisher extends Notifier implements MatrixAggregatab
* If true, save the generated email content to email-ext-message.[txt|html]
*/
public boolean saveOutput = false;

/**
* If true, disables the publisher from running.
*/
public boolean disabled = false;

/**
* How to theTrigger the email if the project is a matrix project.
*/
public MatrixTriggerMode matrixTriggerMode;

@DataBoundConstructor
@Deprecated
public ExtendedEmailPublisher(String project_recipient_list, String project_content_type, String project_default_subject,
String project_default_content, String project_attachments, String project_presend_script,
int project_attach_buildlog, String project_replyto, boolean project_save_output,
Expand All @@ -170,6 +175,26 @@ public ExtendedEmailPublisher(String project_recipient_list, String project_cont
this.configuredTriggers = project_triggers;
this.matrixTriggerMode = matrixTriggerMode;
}

@DataBoundConstructor
public ExtendedEmailPublisher(String project_recipient_list, String project_content_type, String project_default_subject,
String project_default_content, String project_attachments, String project_presend_script,
int project_attach_buildlog, String project_replyto, boolean project_save_output,
List<EmailTrigger> project_triggers, MatrixTriggerMode matrixTriggerMode, boolean project_disabled) {
this.recipientList = project_recipient_list;
this.contentType = project_content_type;
this.defaultSubject = project_default_subject;
this.defaultContent = project_default_content;
this.attachmentsPattern = project_attachments;
this.presendScript = project_presend_script;
this.attachBuildLog = project_attach_buildlog > 0;
this.compressBuildLog = project_attach_buildlog > 1;
this.replyTo = project_replyto;
this.saveOutput = project_save_output;
this.configuredTriggers = project_triggers;
this.matrixTriggerMode = matrixTriggerMode;
this.disabled = project_disabled;
}

public ExtendedEmailPublisher() {

Expand Down Expand Up @@ -229,7 +254,12 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
return true;
}

private boolean _perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, boolean forPreBuild) {
private boolean _perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, boolean forPreBuild) {
if(disabled) {
listener.getLogger().println("Extended Email Publisher is currently disabled in project settings");
return true;
}

boolean emailTriggered = false;
debug(listener.getLogger(), "Checking if email needs to be generated");
final Multimap<String, EmailTrigger> triggered = ArrayListMultimap.create();
Expand Down
Expand Up @@ -10,6 +10,10 @@ d = namespace("jelly:define")
def triggers = hudson.plugins.emailext.plugins.EmailTrigger.all()
def configured = instance != null

f.entry(title: _("Disable Extended Email Publisher"), help: "/plugin/email-ext/help/projectConfig/disablePublisher.html", description: _("Allows the user to disable the publisher, while maintaining the settings")) {
f.checkbox(name: "project_disabled", checked: instance?.disabled)
}

f.entry(title: _("Project Recipient List"), help: "/plugin/email-ext/help/projectConfig/globalRecipientList.html", description: _("Comma-separated list of email address that should receive notifications for this project.")) {
f.textbox(name: "project_recipient_list", value: configured ? instance.recipientList : "\$DEFAULT_RECIPIENTS", checkUrl: "'${rootURL}/publisher/ExtendedEmailPublisher/recipientListRecipientsCheck?value='+encodeURIComponent(this.value)")
}
Expand Down
Expand Up @@ -826,6 +826,29 @@ public void testMultipleTriggersOfSameType()
assertEquals(2, Mailbox.get("mickey@disney.com").size());
}

@Bug(22154)
@Test
public void testProjectDisable() throws Exception {
FreeStyleProject prj = j.createFreeStyleProject("JENKINS-22154");
prj.getPublishersList().add(publisher);

publisher.disabled = true;
publisher.recipientList = "mickey@disney.com";
publisher.configuredTriggers.add(new SuccessTrigger(recProviders, "$DEFAULT_RECIPIENTS",
"$DEFAULT_REPLYTO", "$DEFAULT_SUBJECT", "$DEFAULT_CONTENT", "", 0, "project"));

for(EmailTrigger trigger : publisher.configuredTriggers) {
trigger.getEmail().addRecipientProvider(new ListRecipientProvider());
}

FreeStyleBuild build = prj.scheduleBuild2(0).get();
j.assertBuildStatusSuccess(build);

assertEquals(0, Mailbox.get("mickey@disney.com").size());
assertThat("Publisher is disabled, should have message in build log", build.getLog(100),
hasItem("Extended Email Publisher is currently disabled in project settings"));
}


/* Need to find out why this gets a 404 on the fileprovider.js file
@Test
Expand Down

0 comments on commit aedbab2

Please sign in to comment.