Skip to content
Permalink
Browse files

Fix JENKINS-13563

Added support for content tokens in the attachments area. The
generated string must still be an ANT pattern.
  • Loading branch information
slide committed Jun 1, 2012
1 parent 5fc0aab commit 9c0b9007fc747523e6ee70a66951da0017c49846
@@ -7,6 +7,10 @@
import hudson.model.BuildListener;
import hudson.model.AbstractBuild;

import hudson.plugins.emailext.plugins.ContentBuilder;

import org.apache.commons.lang.StringUtils;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -67,7 +71,7 @@ public String getName() {
}
}

private List<MimeBodyPart> getAttachments(final AbstractBuild<?, ?> build, final BuildListener listener)
private List<MimeBodyPart> getAttachments(ExtendedEmailPublisher publisher, final AbstractBuild<?, ?> build, final BuildListener listener)
throws MessagingException, InterruptedException, IOException {
List<MimeBodyPart> attachments = null;
FilePath ws = build.getWorkspace();
@@ -76,9 +80,10 @@ public String getName() {
ExtendedEmailPublisher.DESCRIPTOR.getMaxAttachmentSize();
if(ws == null) {
listener.error("Error: No workspace found!");
} else if(attachmentsPattern != null && attachmentsPattern.trim().length() > 0) {
} else if(!StringUtils.isBlank(attachmentsPattern)) {
attachments = new ArrayList<MimeBodyPart>();
FilePath[] files = ws.list(attachmentsPattern);

FilePath[] files = ws.list(new ContentBuilder().transformText(attachmentsPattern, publisher, null, build, listener));

for(FilePath file : files) {
if(maxAttachmentSize > 0 &&
@@ -107,9 +112,9 @@ public String getName() {
return attachments;
}

public void attach(Multipart multipart, AbstractBuild<?,?> build, BuildListener listener) {
public void attach(Multipart multipart, ExtendedEmailPublisher publisher, AbstractBuild<?,?> build, BuildListener listener) {
try {
List<MimeBodyPart> attachments = getAttachments(build, listener);
List<MimeBodyPart> attachments = getAttachments(publisher, build, listener);
if(attachments != null) {
for(MimeBodyPart attachment : attachments) {
multipart.addBodyPart(attachment);
@@ -362,8 +362,8 @@ private MimeMessage createMail(EmailType type, AbstractBuild<?, ?> build, BuildL
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(getContent(type, build, msg, listener, charset));
AttachmentUtils attachments = new AttachmentUtils(attachmentsPattern);
attachments.attach(multipart, build, listener);
msg.setContent(multipart);
attachments.attach(multipart, this, build, listener);
msg.setContent(multipart);
EnvVars env = null;
try {
env = build.getEnvironment(listener);

0 comments on commit 9c0b900

Please sign in to comment.