Skip to content
Permalink
Browse files

Fix JENKINS-20384

Added more information to the help files.
  • Loading branch information...
slide committed Apr 14, 2014
1 parent 624bb6e commit 7980566ba93d24b4efd8dcbaddfb52bb5e9a83b5
@@ -1,31 +1,28 @@
package hudson.plugins.emailext;

import hudson.FilePath;
import hudson.model.BuildListener;
import hudson.Launcher;
import hudson.model.AbstractBuild;

import hudson.model.BuildListener;
import hudson.plugins.emailext.plugins.ContentBuilder;
import hudson.plugins.emailext.plugins.ZipDataSource;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.activation.MimetypesFileTypeMap;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.internet.MimeBodyPart;
import org.apache.commons.lang.StringUtils;

/**
* @author acearl
@@ -152,11 +149,16 @@ public String getName() {
}
return attachments;
}


@Deprecated
public void attach(Multipart multipart, ExtendedEmailPublisher publisher, AbstractBuild<?, ?> build, BuildListener listener) {
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, listener);
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, null, listener);
attach(multipart, context);
}

public void attach(Multipart multipart, ExtendedEmailPublisher publisher, AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, launcher, listener);
attach(multipart, context);

}

public void attach(Multipart multipart, ExtendedEmailPublisherContext context) {
@@ -203,16 +205,14 @@ public static void attachBuildLog(ExtendedEmailPublisherContext context, Multipa
}
}

/**
* Attaches the build log to the multipart item.
* @param publisher
* @param multipart
* @param build
* @param listener
* @param compress
*/
@Deprecated
public static void attachBuildLog(ExtendedEmailPublisher publisher, Multipart multipart, AbstractBuild<?, ?> build, BuildListener listener, boolean compress) {
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, listener);
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, null, listener);
attachBuildLog(context, multipart, compress);
}

public static void attachBuildLog(ExtendedEmailPublisher publisher, Multipart multipart, AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, boolean compress) {
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, launcher, listener);
attachBuildLog(context, multipart, compress);
}
}
@@ -2,45 +2,39 @@

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Launcher;
import hudson.matrix.MatrixAggregatable;
import hudson.matrix.MatrixAggregator;
import hudson.matrix.MatrixRun;
import hudson.matrix.MatrixBuild;
import hudson.model.BuildListener;
import hudson.model.Result;
import hudson.matrix.MatrixRun;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.BuildableItemWithBuildWrappers;
import hudson.model.Item;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.plugins.emailext.plugins.ContentBuilder;
import hudson.plugins.emailext.plugins.CssInliner;
import hudson.plugins.emailext.plugins.EmailTrigger;
import hudson.plugins.emailext.plugins.RecipientProvider;
import hudson.plugins.emailext.plugins.content.TriggerNameContent;
import hudson.tasks.BuildStepMonitor;
import hudson.tasks.BuildWrapper;
import hudson.tasks.BuildWrapper.Environment;
import hudson.tasks.MailMessageIdAction;
import hudson.tasks.Mailer;
import hudson.tasks.Notifier;
import hudson.tasks.Publisher;
import hudson.tasks.Mailer;

import jenkins.model.Jenkins;

import groovy.lang.Binding;
import groovy.lang.GroovyShell;
import hudson.FilePath;
import hudson.model.Action;
import hudson.model.Item;
import hudson.model.TaskListener;
import hudson.plugins.emailext.plugins.content.TriggerNameContent;

import jenkins.model.JenkinsLocationConfiguration;
import org.apache.commons.lang.StringUtils;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;

import org.kohsuke.groovy.sandbox.SandboxTransformer;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.ConnectException;
import java.net.SocketException;
@@ -56,7 +50,6 @@
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.MessagingException;
@@ -68,10 +61,14 @@
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import jenkins.model.Jenkins;
import jenkins.model.JenkinsLocationConfiguration;
import org.apache.commons.lang.StringUtils;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.customizers.ImportCustomizer;
import org.jenkinsci.plugins.tokenmacro.TokenMacro;
import org.kohsuke.groovy.sandbox.SandboxTransformer;
import org.kohsuke.stapler.DataBoundConstructor;
import com.google.common.collect.Multimap;
import hudson.plugins.emailext.plugins.RecipientProvider;

/**
* {@link Publisher} that sends notification e-mail.
@@ -220,7 +217,7 @@ public boolean prebuild(AbstractBuild<?, ?> build, BuildListener listener) {
debug(listener.getLogger(), "Checking for pre-build");
if (!(build instanceof MatrixRun) || isExecuteOnMatrixNodes()) {
debug(listener.getLogger(), "Executing pre-build step");
return _perform(build, listener, true);
return _perform(build, null, listener, true);
}
return true;
}
@@ -230,12 +227,12 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
debug(listener.getLogger(), "Checking for post-build");
if (!(build instanceof MatrixRun) || isExecuteOnMatrixNodes()) {
debug(listener.getLogger(), "Performing post-build step");
return _perform(build, listener, false);
return _perform(build, launcher, listener, false);
}
return true;
}

private boolean _perform(AbstractBuild<?, ?> build, BuildListener listener, boolean forPreBuild) {
private boolean _perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener, boolean forPreBuild) {
boolean emailTriggered = false;
debug(listener.getLogger(), "Checking if email needs to be generated");
final Multimap<String, EmailTrigger> triggered = ArrayListMultimap.create();
@@ -275,7 +272,7 @@ private boolean _perform(AbstractBuild<?, ?> build, BuildListener listener, bool
for (String triggerName : triggered.keySet()) {
for (EmailTrigger trigger : triggered.get(triggerName)) {
listener.getLogger().println("Sending email for trigger: " + triggerName);
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(this, build, listener);
final ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(this, build, launcher, listener);
context.setTriggered(triggered);
context.setTrigger(trigger);
sendMail(context);
@@ -499,7 +496,7 @@ private MimeMessage createMail(ExtendedEmailPublisherContext context) throws Mes
// create an empty set of env vars
env = new EnvVars();
}

// Get the recipients from the global list of addresses
Set<InternetAddress> to = new LinkedHashSet<InternetAddress>();
Set<InternetAddress> cc = new LinkedHashSet<InternetAddress>();
@@ -681,7 +678,7 @@ public boolean endBuild() throws InterruptedException, IOException {

// Will be run by parent so we check if needed to be executed by parent
if (getMatrixTriggerMode().forParent) {
return ExtendedEmailPublisher.this._perform(this.build, this.listener, false);
return ExtendedEmailPublisher.this._perform(this.build, this.launcher, this.listener, false);
}
return true;
}
@@ -691,7 +688,7 @@ public boolean startBuild() throws InterruptedException, IOException {
LOGGER.log(Level.FINER, "end build of " + this.build.getDisplayName());
// Will be run by parent so we check if needed to be executed by parent
if (getMatrixTriggerMode().forParent) {
return ExtendedEmailPublisher.this._perform(this.build, this.listener, true);
return ExtendedEmailPublisher.this._perform(this.build, this.launcher, this.listener, true);
}
return true;
}
@@ -1,8 +1,9 @@
package hudson.plugins.emailext;

import com.google.common.collect.Multimap;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.TaskListener;
import hudson.model.BuildListener;
import hudson.plugins.emailext.plugins.EmailTrigger;

/**
@@ -13,12 +14,14 @@
private ExtendedEmailPublisher publisher;
private AbstractBuild<?, ?> build;
private EmailTrigger trigger;
private TaskListener listener;
private BuildListener listener;
private Launcher launcher;
private Multimap<String, EmailTrigger> triggered;

public ExtendedEmailPublisherContext(ExtendedEmailPublisher publisher, AbstractBuild<?, ?> build, TaskListener listener) {
public ExtendedEmailPublisherContext(ExtendedEmailPublisher publisher, AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {
this.publisher = publisher;
this.build = build;
this.launcher = launcher;
this.listener = listener;
}

@@ -46,11 +49,19 @@ protected void setTrigger(EmailTrigger trigger) {
this.trigger = trigger;
}

public TaskListener getListener() {
protected void setLauncher(Launcher launcher) {
this.launcher = launcher;
}

public Launcher getLauncher() {
return launcher;
}

public BuildListener getListener() {
return listener;
}

protected void setListener(TaskListener listener) {
protected void setListener(BuildListener listener) {
this.listener = listener;
}

@@ -3,6 +3,8 @@
import hudson.Extension;
import hudson.matrix.MatrixProject;
import hudson.model.AbstractProject;
import hudson.model.Item;
import hudson.security.Permission;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Publisher;
import hudson.util.FormValidation;
@@ -131,6 +133,8 @@

private boolean enableSecurity = false;

private Permission templateTestPermission = Item.CONFIGURE;

/**
* Enables the "Watch This Job" feature
*/
@@ -292,6 +296,14 @@ public boolean isApplicable(Class<? extends AbstractProject> jobType) {
public String getDefaultPresendScript() {
return defaultPresendScript;
}

public Permission getTemplateTestPermission() {
return templateTestPermission;
}

public void setTemplateTestPermission(Permission templateTestPermission) {
this.templateTestPermission = templateTestPermission;
}

public ExtendedEmailPublisherDescriptor() {
super(ExtendedEmailPublisher.class);
@@ -365,6 +377,8 @@ public boolean configure(StaplerRequest req, JSONObject formData)
} else {
listId = null;
}

templateTestPermission = Permission.fromId(req.getParameter("ext_mailer_template_test_permission"));

save();
return super.configure(req, formData);
@@ -1,7 +1,9 @@
package hudson.plugins.emailext.plugins;

import hudson.CopyOnWrite;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.BuildListener;
import hudson.model.TaskListener;
import hudson.plugins.emailext.ExtendedEmailPublisher;
import hudson.plugins.emailext.ExtendedEmailPublisherContext;
@@ -16,7 +18,6 @@
import net.java.sezpoz.IndexItem;
import org.apache.commons.lang.StringUtils;
import org.jenkinsci.plugins.tokenmacro.MacroEvaluationException;

import org.jenkinsci.plugins.tokenmacro.TokenMacro;

/**
@@ -78,8 +79,13 @@ public static String transformText(String origText, ExtendedEmailPublisherContex
return newText;
}

public static String transformText(String origText, ExtendedEmailPublisher publisher, AbstractBuild<?, ?> build, TaskListener listener) {
ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, listener);
@Deprecated
public static String transformText(String origText, ExtendedEmailPublisher publisher, AbstractBuild<?, ?> build, BuildListener listener) {
return transformText(origText, publisher, build, null, listener);
}

public static String transformText(String origText, ExtendedEmailPublisher publisher, AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) {
ExtendedEmailPublisherContext context = new ExtendedEmailPublisherContext(publisher, build, null, listener);
return transformText(origText, context, null);
}

@@ -12,6 +12,7 @@
import hudson.plugins.emailext.plugins.recipients.ListRecipientProvider;
import java.util.List;

import hudson.tasks.junit.CaseResult;
import org.kohsuke.stapler.DataBoundConstructor;


@@ -34,10 +35,19 @@ public boolean trigger(AbstractBuild<?, ?> build, TaskListener listener) {
AbstractBuild<?,?> previousBuild = ExtendedEmailPublisher.getPreviousBuild(build, listener);
if (previousBuild == null)
return build.getResult() == Result.FAILURE;
if (build.getTestResultAction() == null) return false;

if (build.getTestResultAction() == null)
return false;

if (previousBuild.getTestResultAction() == null)
return build.getTestResultAction().getFailCount() > 0;

for (Object result : build.getTestResultAction().getFailedTests()){
CaseResult res = (CaseResult)result;
if (res.getAge() == 1)
return true;
}

return build.getTestResultAction().getFailCount() >
previousBuild.getTestResultAction().getFailCount();
}
@@ -1,4 +1,4 @@
<div>
An email will be sent if the build status is "Aborted". A build is aborted via the UI or API, but normally requires
some sort of user intervention to occur.
some sort of user intervention to occur. An aborted build is stopped during its execution.
</div>
@@ -1,3 +1,3 @@
<div>
Always triggers an email regardless of the status of the build.
Always triggers an email after the build, regardless of the status of the build.
</div>

0 comments on commit 7980566

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