1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-30 05:59:39 +02:00
sap-jenkins-library/vars/mavenExecuteStaticCodeChecks.groovy
Oliver Feldmann fe2e4e7757
chore: switch to new parameter name (#4968)
* chore: switch to new parameter name

Since warnings-ng plugin version 11 the blameDisabled parameter
has been replaced by skipBlames.
To be compatible with Jenkinsfile Runner we put the recordIssues step
into a try/catch, so no exception is thrown and the build fails.

* docs: improve wording

Co-authored-by: Srinikitha Kondreddy <srinikitha.kondreddy@sap.com>

---------

Co-authored-by: Srinikitha Kondreddy <srinikitha.kondreddy@sap.com>
2024-06-28 13:17:21 +02:00

56 lines
2.1 KiB
Groovy

import com.sap.piper.BuildTool
import com.sap.piper.ConfigurationLoader
import com.sap.piper.DownloadCacheUtils
import com.sap.piper.QualityCheck
import com.sap.piper.ReportAggregator
import groovy.transform.Field
import static com.sap.piper.Prerequisites.checkScript
@Field String METADATA_FILE = 'metadata/mavenExecuteStaticCodeChecks.yaml'
@Field String STEP_NAME = getClass().getName()
void call(Map parameters = [:]) {
final script = checkScript(this, parameters) ?: null
List credentials = []
parameters = DownloadCacheUtils.injectDownloadCacheInParameters(script, parameters, BuildTool.MAVEN)
try {
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, credentials)
} catch (Exception exception) {
error("Maven Static Code Checks execution failed. Please examine the reports which are also available in the Jenkins user interface.")
}
finally {
showIssues(script)
}
}
private showIssues(Script script) {
Map configuration = ConfigurationLoader.stepConfiguration(script, STEP_NAME)
// Every check is executed by default. Only if configured with `false` the check won't be executed
if (!(configuration.spotBugs == false)) {
try {
recordIssues(skipBlames: true,
enabledForFailure: true,
aggregatingResults: false,
tool: spotBugs(pattern: '**/target/spotbugsXml.xml'))
} catch (e) {
echo "recordIssues has failed. Possibly due to an outdated version of the warnings-ng plugin."
e.printStackTrace()
}
ReportAggregator.instance.reportStaticCodeExecution(QualityCheck.FindbugsCheck)
}
if (!(configuration.pmd == false)) {
try {
recordIssues(skipBlames: true,
enabledForFailure: true,
aggregatingResults: false,
tool: pmdParser(pattern: '**/target/pmd.xml'))
} catch (e) {
echo "recordIssues has failed. Possibly due to an outdated version of the warnings-ng plugin."
e.printStackTrace()
}
ReportAggregator.instance.reportStaticCodeExecution(QualityCheck.PmdCheck)
}
}