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
|
2020-08-28 16:11:35 +02:00
|
|
|
import com.sap.piper.StageNameProvider
|
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()
|
2020-08-28 16:11:35 +02:00
|
|
|
@Field String TECHNICAL_STAGE_NAME = 'build'
|
2019-02-05 16:37:59 +02:00
|
|
|
|
|
|
|
@Field Set GENERAL_CONFIG_KEYS = []
|
2019-07-03 10:13:26 +02:00
|
|
|
@Field STAGE_STEP_KEYS = [
|
|
|
|
/** Starts build execution. This is always being executed.*/
|
|
|
|
'buildExecute',
|
|
|
|
/**
|
|
|
|
* Executes stashing of files after build execution.<br /
|
|
|
|
* Build results are stashed with stash name `buildResult`.
|
|
|
|
*
|
|
|
|
* **Note: Please make sure that your build artifacts are contained here since this stash is the foundation for subsequent tests and checks, e.g. deployment to a test landscape.**
|
|
|
|
**/
|
|
|
|
'pipelineStashFilesAfterBuild',
|
2020-11-10 10:18:14 +02:00
|
|
|
/** Executes a Sonar scan.*/
|
|
|
|
'sonarExecuteScan',
|
2019-07-03 10:13:26 +02:00
|
|
|
/** Publishes test results to Jenkins. It will always be active. */
|
|
|
|
'testsPublishResults',
|
|
|
|
/** Publishes check results to Jenkins. It will always be active. */
|
2020-09-07 16:57:01 +02:00
|
|
|
'checksPublishResults',
|
|
|
|
/** Executes static code checks for Maven based projects. The plugins SpotBugs and PMD are used. */
|
|
|
|
'mavenExecuteStaticCodeChecks',
|
|
|
|
/** Executes linting for npm projects. */
|
|
|
|
'npmExecuteLint'
|
2019-07-03 10:13:26 +02:00
|
|
|
]
|
|
|
|
@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 a build is executed which typically also executes tests and code checks.
|
|
|
|
*
|
2020-09-30 09:35:36 +02:00
|
|
|
* The type of build is defined using the configuration `buildTool`, see also step [buildExecute](../steps/buildExecute.md)
|
2019-07-03 10:13:26 +02:00
|
|
|
*
|
|
|
|
*/
|
2019-07-05 16:32:24 +02:00
|
|
|
@GenerateStageDocumentation(defaultStageName = 'Build')
|
2019-02-05 16:37:59 +02:00
|
|
|
void call(Map parameters = [:]) {
|
|
|
|
|
|
|
|
def script = checkScript(this, parameters) ?: this
|
|
|
|
def utils = parameters.juStabUtils ?: new Utils()
|
2020-08-28 16:11:35 +02:00
|
|
|
def stageName = StageNameProvider.instance.getStageName(script, parameters, this)
|
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-09-07 16:57:01 +02:00
|
|
|
.addIfEmpty('npmExecuteLint', script.commonPipelineEnvironment.configuration.runStep?.get(stageName)?.npmExecuteLint)
|
|
|
|
.addIfEmpty('mavenExecuteStaticCodeChecks', script.commonPipelineEnvironment.configuration.runStep?.get(stageName)?.mavenExecuteStaticCodeChecks)
|
2019-02-05 16:37:59 +02:00
|
|
|
.use()
|
|
|
|
|
|
|
|
piperStageWrapper (script: script, stageName: stageName) {
|
|
|
|
|
|
|
|
// telemetry reporting
|
|
|
|
utils.pushToSWA([step: STEP_NAME], config)
|
|
|
|
|
2019-07-03 10:13:26 +02:00
|
|
|
durationMeasure(script: script, measurementName: 'build_duration') {
|
2019-02-05 16:37:59 +02:00
|
|
|
|
2020-08-13 17:01:22 +02:00
|
|
|
buildExecute script: script
|
|
|
|
pipelineStashFilesAfterBuild script: script
|
2019-07-03 10:13:26 +02:00
|
|
|
|
2020-11-10 10:18:14 +02:00
|
|
|
try {
|
|
|
|
testsPublishResults script: script, junit: [updateResults: true]
|
|
|
|
checksPublishResults script: script
|
|
|
|
} finally {
|
|
|
|
if (config.sonarExecuteScan) {
|
|
|
|
sonarExecuteScan script: script
|
|
|
|
}
|
|
|
|
}
|
2019-07-03 10:13:26 +02:00
|
|
|
}
|
2020-09-07 16:57:01 +02:00
|
|
|
|
|
|
|
if (config.mavenExecuteStaticCodeChecks) {
|
|
|
|
durationMeasure(script: script, measurementName: 'staticCodeChecks_duration') {
|
|
|
|
mavenExecuteStaticCodeChecks(script: script)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.npmExecuteLint) {
|
|
|
|
durationMeasure(script: script, measurementName: 'npmExecuteLint_duration') {
|
|
|
|
npmExecuteLint script: script
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 16:37:59 +02:00
|
|
|
}
|
|
|
|
}
|