Skip to content

Commit

Permalink
Merge pull request #1 from jenkinsci/pipeline
Browse files Browse the repository at this point in the history
[JENKINS-50047] add pipeline support
  • Loading branch information
irissmann committed Apr 4, 2018
2 parents 0ae9694 + a4cc7d0 commit d4d6bfd
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/main/java/org/jenkinsci/plugins/arachni/ArachniScanner.java
Expand Up @@ -10,6 +10,7 @@

import javax.servlet.ServletException;

import org.jenkinsci.Symbol;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.QueryParameter;
import org.slf4j.Logger;
Expand All @@ -21,17 +22,19 @@
import de.irissmann.arachni.client.request.Scope;
import de.irissmann.arachni.client.response.ScanResponse;
import de.irissmann.arachni.client.rest.ArachniRestClientBuilder;
import hudson.AbortException;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.BuildListener;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.tasks.BuildStepDescriptor;
import hudson.tasks.Builder;
import hudson.util.FormValidation;
import jenkins.tasks.SimpleBuildStep;

public class ArachniScanner extends Builder {
public class ArachniScanner extends Builder implements SimpleBuildStep {
Logger log = LoggerFactory.getLogger(ArachniScanner.class);

private String url;
Expand All @@ -54,6 +57,7 @@ public ArachniScopeProperty getScope() {
return scope;
}

@Symbol("arachniScanner")
@Extension
public static class DescriptorImpl extends BuildStepDescriptor<Builder> {
public DescriptorImpl() {
Expand Down Expand Up @@ -81,8 +85,8 @@ public FormValidation doCheckUrl(@QueryParameter String value) throws IOExceptio
}

@Override
public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener)
throws InterruptedException {
public void perform(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener)
throws InterruptedException, IOException {
console = listener.getLogger();
ArachniPluginConfiguration config = ArachniPluginConfiguration.get();
String arachniUrl = config.getArachniServerUrl();
Expand Down Expand Up @@ -118,11 +122,10 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
}
}

FilePath arachniPath = build.getWorkspace();
log.debug("Path for arachni results: {}", arachniPath);
log.debug("Path for arachni results: {}", workspace);

if (arachniPath != null) {
File reportFile = new File(arachniPath.getRemote(), "arachni-report-html.zip");
if (workspace != null) {
File reportFile = new File(workspace.getRemote(), "arachni-report-html.zip");
if (! reportFile.exists()) {
if (! reportFile.createNewFile()) {
throw new Exception("Could not create file " + reportFile.toString());
Expand All @@ -134,7 +137,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
} catch (Exception exception) {
log.warn("Error when start Arachni Security Scan", exception);
console.println(exception.getMessage());
return false;
throw new AbortException();
} finally {
try {
if (outstream != null) {
Expand All @@ -143,11 +146,9 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
} catch (IOException e) {
log.warn("Error when start Arachni Security Scan", e);
console.println(e.getMessage());
return false;
throw new AbortException();
}
}

return true;
}

protected void shutdownScan() throws IOException {
Expand Down

0 comments on commit d4d6bfd

Please sign in to comment.