diff --git a/src/main/java/com/fortify/plugin/jenkins/FindExecutableRemoteService.java b/src/main/java/com/fortify/plugin/jenkins/FindExecutableRemoteService.java index eb519c8..f0d8296 100644 --- a/src/main/java/com/fortify/plugin/jenkins/FindExecutableRemoteService.java +++ b/src/main/java/com/fortify/plugin/jenkins/FindExecutableRemoteService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * (c) Copyright 2019 Micro Focus or one of its affiliates. + * (c) Copyright 2020 Micro Focus or one of its affiliates. * * Licensed under the MIT License (the "License"); * you may not use this file except in compliance with the License. @@ -24,10 +24,10 @@ import hudson.remoting.VirtualChannel; public class FindExecutableRemoteService implements FilePath.FileCallable { - private String filename; + private final String filename; private String home; private String path; - private FilePath workspace; + private final FilePath workspace; /** * Searches the PATH on the remote machine @@ -62,6 +62,10 @@ public String invoke(File file, VirtualChannel channel) throws IOException { return s; } } + // if no path is passed in, get the system path + if (path == null) { + path = System.getenv("PATH"); + } File f = PathUtils.locateFileInPath(filename, path); if (f != null) { return f.getPath(); diff --git a/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanArguments.java b/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanArguments.java index 20bc85e..1aaba5b 100644 --- a/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanArguments.java +++ b/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanArguments.java @@ -14,6 +14,7 @@ import org.kohsuke.stapler.*; import javax.annotation.Nonnull; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; @@ -49,7 +50,13 @@ public void perform(@Nonnull Run run, @Nonnull FilePath filePath, @Nonnull PrintStream log = taskListener.getLogger(); log.println("Fortify Jenkins plugin v " + VERSION); log.println("Launching Fortify scancentral arguments command"); - String cloudscanExec = getScancentralExecutable(run, filePath, launcher, taskListener); + String cloudscanExec; + try { + cloudscanExec = getScancentralExecutable(run, filePath, launcher, taskListener); + } catch (FileNotFoundException ex) { + log.println("WARNING: Cannot find scancentral executable"); + cloudscanExec = getCloudScanExecutable(run, filePath, launcher, taskListener); + } EnvVars vars = run.getEnvironment(taskListener); ArrayList args = new ArrayList(2); @@ -70,11 +77,11 @@ public void perform(@Nonnull Run run, @Nonnull FilePath filePath, @Nonnull Launcher.ProcStarter ps = launcher.decorateByEnv(vars).launch().pwd(filePath).cmds(args).envs(vars) .stdout(taskListener.getLogger()).stderr(taskListener.getLogger()); int exitcode = ps.join(); - log.println("Fortify cloudscan arguments command completed with exit code: " + exitcode); + log.println("Fortify scancentral arguments command completed with exit code: " + exitcode); if (exitcode != 0) { run.setResult(Result.FAILURE); - throw new AbortException("Fortify cloudscan arguments command execution failed."); + throw new AbortException("Fortify scancentral arguments command execution failed."); } } @@ -112,7 +119,7 @@ protected Execution(CloudScanArguments csArguments, StepContext context) { @Override protected Void run() throws Exception { - getContext().get(TaskListener.class).getLogger().println("Running CloudScan arguments step"); + getContext().get(TaskListener.class).getLogger().println("Running ScanCentral arguments step"); if (!getContext().get(FilePath.class).exists()) { getContext().get(FilePath.class).mkdirs(); } diff --git a/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanMbs.java b/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanMbs.java index 76a4dfa..85f58ce 100644 --- a/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanMbs.java +++ b/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanMbs.java @@ -19,6 +19,7 @@ import javax.annotation.Nonnull; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; @@ -116,7 +117,13 @@ public void perform(@Nonnull Run run, @Nonnull FilePath filePath, @Nonnull log.println("Fortify Jenkins plugin v " + VERSION); log.println("Performing Fortify remote scan"); String projectRoot = filePath.getRemote() + File.separator + ".fortify"; - String cloudscanExec = getScancentralExecutable(run, filePath, launcher, taskListener); + String cloudscanExec; + try { + cloudscanExec = getScancentralExecutable(run, filePath, launcher, taskListener); + } catch (FileNotFoundException ex) { + log.println("WARNING: Cannot find scancentral executable"); + cloudscanExec = getCloudScanExecutable(run, filePath, launcher, taskListener); + } EnvVars vars = run.getEnvironment(taskListener); ArrayList args = new ArrayList(2); diff --git a/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanStart.java b/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanStart.java index ab1689a..0dce7d5 100644 --- a/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanStart.java +++ b/src/main/java/com/fortify/plugin/jenkins/steps/CloudScanStart.java @@ -19,6 +19,7 @@ import javax.annotation.Nonnull; import java.io.File; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; @@ -180,7 +181,13 @@ public void perform(@Nonnull Run run, @Nonnull FilePath filePath, @Nonnull log.println("Fortify Jenkins plugin v " + VERSION); log.println("Performing Fortify remote analysis"); String projectRoot = filePath.getRemote() + File.separator + ".fortify"; - String cloudscanExec = getScancentralExecutable(run, filePath, launcher, taskListener); + String cloudscanExec; + try { + cloudscanExec = getScancentralExecutable(run, filePath, launcher, taskListener); + } catch (FileNotFoundException ex) { + log.println("WARNING: Cannot find scancentral executable"); + cloudscanExec = getCloudScanExecutable(run, filePath, launcher, taskListener); + } EnvVars vars = run.getEnvironment(taskListener); ArrayList args = new ArrayList(2); diff --git a/src/main/java/com/fortify/plugin/jenkins/steps/FortifyCloudScanStep.java b/src/main/java/com/fortify/plugin/jenkins/steps/FortifyCloudScanStep.java index fd64d30..9f5eedf 100644 --- a/src/main/java/com/fortify/plugin/jenkins/steps/FortifyCloudScanStep.java +++ b/src/main/java/com/fortify/plugin/jenkins/steps/FortifyCloudScanStep.java @@ -6,6 +6,7 @@ import hudson.model.TaskListener; import org.kohsuke.stapler.DataBoundSetter; +import java.io.FileNotFoundException; import java.io.IOException; public abstract class FortifyCloudScanStep extends FortifyStep { @@ -26,22 +27,14 @@ public String getResolvedScanArgs(TaskListener listener) { protected String getCloudScanExecutable(Run build, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException { + listener.getLogger().println("Checking for cloudscan executable"); return getExecutable("cloudscan" + (launcher.isUnix() ? "" : ".bat"), true, build, workspace, launcher, listener, null); } - /* Look for scancentral executable in Jenkins environment, if not found, get the old cloudscan executable. It's considered not found - * if the getExecutable() returns just the filename rather than the full path.*/ protected String getScancentralExecutable(Run build, FilePath workspace, Launcher launcher, TaskListener listener) throws InterruptedException, IOException { - String filename = "scancentral" + (launcher.isUnix() ? "" : ".bat"); - String msg = "Checking for cloudscan executable"; - String exec = getExecutable(filename, true, build, workspace, launcher, - listener, msg); - if (exec.equals(filename)) { - return getCloudScanExecutable(build, workspace, launcher, listener); - } else { - return exec; - } + return getExecutable("scancentral" + (launcher.isUnix() ? "" : ".bat"), true, build, workspace, launcher, + listener, null); } } diff --git a/src/main/java/com/fortify/plugin/jenkins/steps/FortifyStep.java b/src/main/java/com/fortify/plugin/jenkins/steps/FortifyStep.java index 16edbf3..eab1e64 100644 --- a/src/main/java/com/fortify/plugin/jenkins/steps/FortifyStep.java +++ b/src/main/java/com/fortify/plugin/jenkins/steps/FortifyStep.java @@ -1,5 +1,5 @@ /******************************************************************************* - * (c) Copyright 2019 Micro Focus or one of its affiliates. + * (c) Copyright 2020 Micro Focus or one of its affiliates. * * Licensed under the MIT License (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ *******************************************************************************/ package com.fortify.plugin.jenkins.steps; +import java.io.FileNotFoundException; import java.io.IOException; import java.nio.charset.Charset; import java.util.Collection; @@ -62,7 +63,7 @@ protected void setLastBuild(Run lastBuild) { * @param launcher * @param listener * @param msg - * @return found executable or filename if not found + * @return found executable * @throws InterruptedException * @throws IOException */ @@ -71,6 +72,7 @@ protected String getExecutable(String filename, boolean checkFortifyHome, Run entry : env.entrySet()) { String key = entry.getKey(); if ("FORTIFY_HOME".equals(key)) { @@ -83,13 +85,7 @@ protected String getExecutable(String filename, boolean checkFortifyHome, Run