2019-02-05 16:37:59 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2019-07-03 10:13:26 +02:00
|
|
|
import com.sap.piper.GenerateStageDocumentation
|
2019-02-05 16:37:59 +02:00
|
|
|
import com.sap.piper.Utils
|
|
|
|
import groovy.transform.Field
|
|
|
|
|
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
|
|
|
@Field String STEP_NAME = getClass().getName()
|
|
|
|
|
|
|
|
@Field Set GENERAL_CONFIG_KEYS = []
|
2019-07-03 10:13:26 +02:00
|
|
|
@Field STAGE_STEP_KEYS = [
|
2020-06-19 12:35:02 +02:00
|
|
|
/** Executes a Checkmarx scan */
|
|
|
|
'checkmarxExecuteScan',
|
|
|
|
/** Executes a Fortify scan */
|
|
|
|
'fortifyExecuteScan',
|
2019-07-03 10:13:26 +02:00
|
|
|
/** Executes a WhiteSource scan */
|
|
|
|
'whitesourceExecuteScan'
|
|
|
|
]
|
|
|
|
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus(STAGE_STEP_KEYS)
|
2019-02-05 16:37:59 +02:00
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
2019-07-03 10:13:26 +02:00
|
|
|
/**
|
|
|
|
* In this stage important security-relevant checks will be conducted.<br />
|
|
|
|
* This is to achieve a decent level of security for your application.
|
|
|
|
*/
|
|
|
|
@GenerateStageDocumentation(defaultStageName = 'Security')
|
2019-02-05 16:37:59 +02:00
|
|
|
void call(Map parameters = [:]) {
|
|
|
|
def script = checkScript(this, parameters) ?: this
|
|
|
|
def utils = parameters.juStabUtils ?: new Utils()
|
|
|
|
|
|
|
|
def stageName = parameters.stageName?:env.STAGE_NAME
|
|
|
|
|
2020-06-24 08:21:41 +02:00
|
|
|
def securityScanMap = [:]
|
|
|
|
|
2019-02-05 16:37:59 +02:00
|
|
|
Map config = ConfigurationHelper.newInstance(this)
|
|
|
|
.loadStepDefaults()
|
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS)
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
2020-06-19 12:35:02 +02:00
|
|
|
.addIfEmpty('checkmarxExecuteScan', script.commonPipelineEnvironment.configuration.runStep?.get(stageName)?.checkmarxExecuteScan)
|
|
|
|
.addIfEmpty('fortifyExecuteScan', script.commonPipelineEnvironment.configuration.runStep?.get(stageName)?.fortifyExecuteScan)
|
2019-07-03 10:13:26 +02:00
|
|
|
.addIfEmpty('whitesourceExecuteScan', script.commonPipelineEnvironment.configuration.runStep?.get(stageName)?.whitesourceExecuteScan)
|
2019-02-05 16:37:59 +02:00
|
|
|
.use()
|
|
|
|
piperStageWrapper (script: script, stageName: stageName) {
|
2020-06-19 12:35:02 +02:00
|
|
|
if (config.checkmarxExecuteScan) {
|
|
|
|
securityScanMap['Checkmarx'] = {
|
|
|
|
node(config.nodeLabel) {
|
|
|
|
try{
|
|
|
|
durationMeasure(script: script, measurementName: 'checkmarx_duration') {
|
|
|
|
checkmarxExecuteScan script: script
|
|
|
|
}
|
|
|
|
}finally{
|
|
|
|
deleteDir()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.fortifyExecuteScan) {
|
|
|
|
securityScanMap['Fortify'] = {
|
|
|
|
node(config.nodeLabel) {
|
|
|
|
try{
|
|
|
|
durationMeasure(script: script, measurementName: 'fortify_duration') {
|
|
|
|
fortifyExecuteScan script: script
|
|
|
|
}
|
|
|
|
}finally{
|
|
|
|
deleteDir()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 16:37:59 +02:00
|
|
|
|
2019-07-03 10:13:26 +02:00
|
|
|
if (config.whitesourceExecuteScan) {
|
2020-06-19 12:35:02 +02:00
|
|
|
securityScanMap['WhiteSource'] = {
|
|
|
|
node(config.nodeLabel) {
|
|
|
|
try{
|
|
|
|
durationMeasure(script: script, measurementName: 'whitesource_duration') {
|
|
|
|
whitesourceExecuteScan script: script
|
|
|
|
}
|
|
|
|
}finally{
|
|
|
|
deleteDir()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (securityScanMap.size() > 0) {
|
2020-06-24 08:21:41 +02:00
|
|
|
// telemetry reporting
|
|
|
|
utils.pushToSWA([step: STEP_NAME], config)
|
2020-06-19 12:35:02 +02:00
|
|
|
|
2020-06-24 08:21:41 +02:00
|
|
|
parallel securityScanMap.plus([failFast: false])
|
2019-07-03 10:13:26 +02:00
|
|
|
}
|
2019-02-05 16:37:59 +02:00
|
|
|
}
|
|
|
|
}
|