1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/cmd/detectExecuteScan.go
Marcus Holl 4f2ba73314
[refactoring] move the shell/command related interfaces into pkg/command (#1737)
* [refactoring] move the shell/command related interfaces into pkg/command

otherwise we are not able to use the corresponding mocks for the items contained in pkg since
these interfaces are not visible from the pkg folder

Co-authored-by: Daniel Kurzynski <daniel.kurzynski@sap.com>
2020-07-01 11:28:16 +02:00

64 lines
2.1 KiB
Go

package cmd
import (
"fmt"
"strings"
sliceUtils "github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
)
func detectExecuteScan(config detectExecuteScanOptions, telemetryData *telemetry.CustomData) {
c := command.Command{}
// reroute command output to logging framework
c.Stdout(log.Writer())
c.Stderr(log.Writer())
runDetect(config, &c)
}
func runDetect(config detectExecuteScanOptions, command command.ShellRunner) {
// detect execution details, see https://synopsys.atlassian.net/wiki/spaces/INTDOCS/pages/88440888/Sample+Synopsys+Detect+Scan+Configuration+Scenarios+for+Black+Duck
args := []string{"bash <(curl -s https://detect.synopsys.com/detect.sh)"}
args = addDetectArgs(args, config)
script := strings.Join(args, " ")
command.SetDir(".")
command.SetEnv([]string{"BLACKDUCK_SKIP_PHONE_HOME=true"})
err := command.RunShell("/bin/bash", script)
if err != nil {
log.Entry().
WithError(err).
Fatal("failed to execute detect scan")
}
}
func addDetectArgs(args []string, config detectExecuteScanOptions) []string {
args = append(args, config.ScanProperties...)
args = append(args, fmt.Sprintf("--blackduck.url=%v", config.ServerURL))
args = append(args, fmt.Sprintf("--blackduck.api.token=%v", config.APIToken))
args = append(args, fmt.Sprintf("--detect.project.name=%v", config.ProjectName))
args = append(args, fmt.Sprintf("--detect.project.version.name=%v", config.ProjectVersion))
codeLocation := config.CodeLocation
if len(codeLocation) == 0 && len(config.ProjectName) > 0 {
codeLocation = fmt.Sprintf("%v/%v", config.ProjectName, config.ProjectVersion)
}
args = append(args, fmt.Sprintf("--detect.code.location.name=%v", codeLocation))
if sliceUtils.ContainsString(config.Scanners, "signature") {
args = append(args, fmt.Sprintf("--detect.blackduck.signature.scanner.paths=%v", strings.Join(config.ScanPaths, ",")))
}
if sliceUtils.ContainsString(config.Scanners, "source") {
args = append(args, fmt.Sprintf("--detect.source.path=%v", config.ScanPaths[0]))
}
return args
}