Skip to content
Permalink
Browse files

Fix JENKINS-22154 - Add disable at project level

  • Loading branch information...
slide committed Jul 11, 2014
1 parent e542f6e commit aedbab2e9230fcfc5c9e242a5389df044204bac8
@@ -146,13 +146,18 @@
* 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,
@@ -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() {

@@ -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();
@@ -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)")
}
@@ -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

0 comments on commit aedbab2

Please sign in to comment.
You can’t perform that action at this time.