Skip to content

Commit

Permalink
Merge pull request #347 from jenkinsci/bug/createReportInWorkspase
Browse files Browse the repository at this point in the history
Save report in workspace folder (AST-74894)
  • Loading branch information
greensd4 authored Dec 4, 2024
2 parents e20f047 + c00e93f commit 2768d8a
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/main/java/com/checkmarx/jenkins/CheckmarxScanBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void close() throws IOException {
}

private void saveInArtifactAdditionalReports(ScanConfig scanConfig, FilePath workspace, EnvVars envVars, Launcher launcher, TaskListener listener, Run<?, ?> run) throws IOException, InterruptedException {
if (scanConfig.getAdditionalOptions().contains("--report-format")) {
if (scanConfig.getAdditionalOptions() != null && scanConfig.getAdditionalOptions().contains("--report-format")) {
try {
String additionalOptions = scanConfig.getAdditionalOptions();

Expand All @@ -382,9 +382,8 @@ private void saveInArtifactAdditionalReports(ScanConfig scanConfig, FilePath wor
String fileName = (additionalOptions.contains("--output-name")
? extractOptionValue(additionalOptions, "--output-name")
: PluginUtils.defaultOutputName) + "." + formatType;
String outputPath = additionalOptions.contains("--output-path")
? extractOptionValue(additionalOptions, "--output-path")
: ".";
String outputPath = extractOptionValue(additionalOptions, "--output-path");

String fullFilePath = new File(outputPath, fileName).getPath();
FilePath destinationPath = workspace.child(fileName);

Expand All @@ -408,7 +407,15 @@ private String extractOptionValue(String options, String optionKey) {
if (options.contains(optionKey)) {
String[] parts = options.split(optionKey, 2);
if (parts.length > 1) {
return parts[1].trim().split(" ")[0];
String remaining = parts[1].trim();
if (remaining.startsWith("\"")) {
int endIndex = remaining.indexOf("\"", 1);
if (endIndex > 0) {
return remaining.substring(1, endIndex);
}
} else {
return remaining.split(" ")[0];
}
}
}
return "";
Expand Down Expand Up @@ -509,6 +516,9 @@ private ScanConfig resolveConfiguration(Run<?, ?> run, FilePath workspace, Check

String additionalOptions = getUseOwnAdditionalOptions() ? getAdditionalOptions() : descriptor.getAdditionalOptions();
if (fixEmptyAndTrim(additionalOptions) != null) {
if (additionalOptions.contains("--report-format") && !additionalOptions.contains("--output-path")) {
additionalOptions += String.format(" --output-path \"%s\"", workspace.getRemote());
}
scanConfig.setAdditionalOptions(envVars.expand(additionalOptions));
}

Expand Down

0 comments on commit 2768d8a

Please sign in to comment.