Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevention of race conditions if used in a pipeline with parallel #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/main/java/hudson/plugins/mstest/MSTestPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.UUID;
import jenkins.MasterToSlaveFileCallable;
import jenkins.tasks.SimpleBuildStep;
import org.apache.tools.ant.DirectoryScanner;
Expand Down Expand Up @@ -141,17 +142,18 @@ public void perform(final @NonNull Run<?, ?> build, @NonNull FilePath workspace,

buildTime = build.getTimestamp().getTimeInMillis();

String junitReportDir = MSTestTransformer.JUNIT_REPORTS_PATH_DIR_PREFIX + "-" + UUID.randomUUID();
String[] matchingFiles = resolveTestReports(testResultsFile, build, workspace, listener);
MSTestReportConverter converter = new MSTestReportConverter(listener);
MSTestTransformer transformer = new MSTestTransformer(matchingFiles, converter, listener,
failOnError);
failOnError, junitReportDir);
boolean result = workspace.act(transformer);

if (result) {
// Run the JUnit test archiver
recordTestResult(MSTestTransformer.JUNIT_REPORTS_PATH + "/TEST-*.xml", build, workspace,
listener);
workspace.child(MSTestTransformer.JUNIT_REPORTS_PATH).deleteRecursive();
recordTestResult(junitReportDir + "/TEST-*.xml", build, workspace,
listener);
workspace.child(junitReportDir).deleteRecursive();
} else {
throw new AbortException("Unable to transform the MSTest report.");
}
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/hudson/plugins/mstest/MSTestTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,27 @@
*/
public class MSTestTransformer extends MasterToSlaveFileCallable<Boolean> {

static final String JUNIT_REPORTS_PATH = "temporary-junit-reports";
static final String JUNIT_REPORTS_PATH_DIR_PREFIX = "temp-junit-reports";
private static final long serialVersionUID = 1L;
private final TaskListener listener;
private final boolean failOnError;
private final String junitReportDir;

private final MSTestReportConverter unitReportTransformer;
private final String[] msTestFiles;

MSTestTransformer(String[] msTestFiles, @NonNull MSTestReportConverter unitReportTransformer,
@NonNull TaskListener listener, boolean failOnError) {
this(msTestFiles, unitReportTransformer, listener, failOnError, null);
}

MSTestTransformer(String[] msTestFiles, @NonNull MSTestReportConverter unitReportTransformer,
@NonNull TaskListener listener, boolean failOnError, String junitReportDir) {
this.msTestFiles = msTestFiles;
this.unitReportTransformer = unitReportTransformer;
this.listener = listener;
this.failOnError = failOnError;
this.junitReportDir = (junitReportDir != null) ? junitReportDir : JUNIT_REPORTS_PATH_DIR_PREFIX; // Keep tests calls simple
}

/**
Expand All @@ -59,7 +66,7 @@ public Boolean invoke(File ws, VirtualChannel channel) throws IOException {
.format("No MSTest TRX test report files were found. Configuration error?"));
}

File junitOutputPath = new File(ws, JUNIT_REPORTS_PATH);
File junitOutputPath = new File(ws, junitReportDir);
boolean success = FileOperator.safeCreateFolder(junitOutputPath, logger);
if (!success) {
return Boolean.FALSE;
Expand Down