Skip to content

Commit

Permalink
Add attachments from the junit-attachments plugin into Jira attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
imonteroperez committed Apr 21, 2024
1 parent 2d0bdac commit 28922e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>junit-attachments</artifactId>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder;
import com.atlassian.jira.rest.client.api.domain.util.ErrorCollection;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.model.Job;
import hudson.plugins.junitattachments.AttachmentPublisher;
import hudson.tasks.junit.CaseResult;
import hudson.tasks.test.TestResult;
import io.atlassian.util.concurrent.Promise;
Expand All @@ -34,6 +36,7 @@
import org.jenkinsci.plugins.JiraTestResultReporter.config.AbstractFields;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.*;
Expand Down Expand Up @@ -230,6 +233,20 @@ private static String createIssueInput(IssueInput issueInput, CaseResult test) {
if (StringUtils.isNotBlank(test.getErrorDetails())) {
issueClient.addAttachment(attachmentsUri, new ByteArrayInputStream(test.getErrorDetails().getBytes(StandardCharsets.UTF_8)), "details.out").claim();
}

FilePath attachmentStorage = AttachmentPublisher.getAttachmentPath(test.getRun());
JiraUtils.log(attachmentStorage.getName());
try {
if (attachmentStorage.exists()) {
FilePath attachmentPath = AttachmentPublisher.getAttachmentPath(attachmentStorage, test.getClassName());
JiraUtils.log(attachmentPath.getName());
for (FilePath file : attachmentPath.list()) {
issueClient.addAttachment(attachmentsUri, file.read(), file.getName()).claim();
}
}
} catch (IOException | InterruptedException e) {
JiraUtils.log(String.format("Unable to access to attachment storage for %s:%s", test.getName(), test.getRun().getId()));
}
return key;
}

Expand Down

0 comments on commit 28922e1

Please sign in to comment.