1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-02-21 19:48:53 +02:00

Fix runStep condition for mavenExecuteStaticCodeChecks (#2009)

This change fixes the step mavenExecuteStaticCodeChecks to skip execution
if no tool is configured. Previously, the step was executed even when both 
supported tools, i.e., PMD and SpotBugs were disabled.
This commit is contained in:
Kevin Hudemann 2020-09-11 16:16:00 +02:00 committed by GitHub
parent f1cfca2e76
commit a57e3bf0ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -23,7 +23,8 @@ func runMavenStaticCodeChecks(config *mavenExecuteStaticCodeChecksOptions, telem
var goals []string
if !config.SpotBugs && !config.Pmd {
log.Entry().Fatal("Neither SpotBugs nor Pmd are configured. At least one of those tools have to be enabled")
log.Entry().Warnf("Neither SpotBugs nor Pmd are configured. Skipping step execution")
return nil
}
if testModulesExcludes := maven.GetTestModulesExcludes(); testModulesExcludes != nil {

View File

@ -4,8 +4,6 @@ import (
"os"
"testing"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/mock"
"github.com/SAP/jenkins-library/pkg/maven"
@ -51,16 +49,15 @@ func TestRunMavenStaticCodeChecks(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, expected, execMockRunner.Calls[0])
})
t.Run("should log fatal if all tools are turned off", func(t *testing.T) {
var hasFailed bool
log.Entry().Logger.ExitFunc = func(int) { hasFailed = true }
t.Run("should warn and skip execution if all tools are turned off", func(t *testing.T) {
execMockRunner := mock.ExecMockRunner{}
config := mavenExecuteStaticCodeChecksOptions{
SpotBugs: false,
Pmd: false,
}
_ = runMavenStaticCodeChecks(&config, nil, &execMockRunner)
assert.True(t, hasFailed, "expected command to exit with fatal")
err := runMavenStaticCodeChecks(&config, nil, &execMockRunner)
assert.Nil(t, err)
assert.Nil(t, execMockRunner.Calls)
})
}