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

Save report in workspace folder (AST-74894) #347

Merged
merged 3 commits into from
Dec 4, 2024
Merged
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
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
Loading