Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package com.ibm.appscan.jenkins.plugin.actions;

import java.io.File;
import java.io.IOException;

import hudson.model.AbstractBuild;
Expand All @@ -21,13 +22,15 @@ public class ResultsRetriever extends AppScanAction implements RunAction2 {
private final AbstractBuild<?,?> m_build;
private IResultsProvider m_provider;
private String m_name;
private String m_reportLocation;

@DataBoundConstructor
public ResultsRetriever(AbstractBuild<?,?> build, IResultsProvider provider, String scanName) {
public ResultsRetriever(AbstractBuild<?,?> build, IResultsProvider provider, String scanName, String reportLocation) {
super(build.getProject());
m_build = build;
m_provider = provider;
m_name = scanName;
m_reportLocation = reportLocation;
}

@Override
Expand Down Expand Up @@ -56,6 +59,8 @@ public boolean getHasResults() {
public boolean checkResults(Run<?, ?> r) {
if(r.getAllActions().contains(this) && m_provider.hasResults()) {
r.getActions().remove(this); //We need to remove this action from the build, but getAllActions() returns a read-only list.
if(m_reportLocation!=null && (new File(m_reportLocation).isDirectory() || new File(m_reportLocation).getParentFile().exists()))
m_provider.getResultsFile(getReportName(), null);
r.addAction(createResults());
try {
r.save();
Expand All @@ -66,6 +71,16 @@ public boolean checkResults(Run<?, ?> r) {
return false;
}

private File getReportName() {
File file = new File(m_reportLocation);
if(file.getName().indexOf(".") == -1) {
if(file.isDirectory())
return new File(m_reportLocation, "report." + m_provider.getResultsFormat().toLowerCase());
return new File(m_reportLocation + "_report." + m_provider.getResultsFormat().toLowerCase());
}
return new File(m_reportLocation);
}

private ScanResults createResults() {
return new ScanResults(
m_build,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ public class AppScanBuildStep extends Builder implements Serializable {
private String m_target;
private String m_application;
private String m_credentials;
private String m_reportLocation;
private List<FailureCondition> m_failureConditions;
private boolean m_emailNotification;
private boolean m_wait;
private boolean m_failBuild;
private boolean m_saveReport;
private IAuthenticationProvider m_authProvider;

@DataBoundConstructor
public AppScanBuildStep(Scanner scanner, String name, String type, String target, String application, String credentials, List<FailureCondition> failureConditions, boolean failBuild, boolean wait, boolean email) {
public AppScanBuildStep(Scanner scanner, String name, String type, String target, String application, String credentials, List<FailureCondition> failureConditions, boolean failBuild, boolean wait, boolean email, boolean saveReport, String reportLocation) {
m_scanner = scanner;
m_name = (name == null || name.trim().equals("")) ? application.replaceAll(" ", "") + ThreadLocalRandom.current().nextInt(0, 10000) : name; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
m_type = scanner.getType();
Expand All @@ -88,6 +90,8 @@ public AppScanBuildStep(Scanner scanner, String name, String type, String target
m_emailNotification = email;
m_wait = wait;
m_failBuild = failBuild;
m_saveReport = saveReport;
m_reportLocation = reportLocation;
}

public Scanner getScanner() {
Expand Down Expand Up @@ -132,6 +136,14 @@ public boolean getEmail() {
return m_emailNotification;
}

public boolean getSaveReport() {
return m_saveReport;
}

public String getReportLocation() {
return m_reportLocation;
}

@Override
public DescriptorImpl getDescriptor() {
return (DescriptorImpl)super.getDescriptor();
Expand Down Expand Up @@ -181,7 +193,7 @@ public IResultsProvider call() throws AbortException {

});

build.addAction(new ResultsRetriever(build, provider, m_name));
build.addAction(new ResultsRetriever(build, provider, m_name, m_reportLocation));

if(m_wait && shouldFailBuild(provider))
throw new AbortException(Messages.error_threshold_exceeded());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ LICENSE: Apache License, Version 2.0 https://www.apache.org/licenses/LICENSE-2.0
<f:select />
</f:entry>

<f:entry title="${%label.name}" field="name">
<f:textbox />
</f:entry>
<f:entry title="${%label.name}" field="name">
<f:textbox />
</f:entry>

<f:dropdownDescriptorSelector title="${%label.type}" field="scanner"/>

<f:entry field="email">
<f:checkbox title="${%label.email}"/>
</f:entry>

<f:optionalBlock title="${%label.save.report}" field="saveReport" inline="true">
<f:entry title="${%label.report.location}" field="reportLocation">
<f:textbox />
</f:entry>
</f:optionalBlock>

<f:entry field="wait">
<f:checkbox title="${%label.wait}" onclick="waitClicked(this);" name="wait"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ label.email=Email Notification
label.wait=Suspend job until security analysis completes
label.fail.build=Fail build if:
label.add.condition=Add Condition
label.save.report=Save Report
label.report.location=Location