From a035690f3da86cf1b9d0b9a37719b5c6391e7cf1 Mon Sep 17 00:00:00 2001 From: Kevin Hudemann Date: Thu, 27 Aug 2020 16:17:06 +0200 Subject: [PATCH] Update Cloud SDK stage defaults (#1959) This change updates the Cloud SDK stage defaults, makes the piperPipelineStageMavenStaticCodeChecks use the step condition and adds the onlyRunInProductiveBranch configuration option to npmExecuteEndToEndTests step. --- .../pipeline/cloudSdkStageDefaults.yml | 104 ++++++++++++++++-- vars/npmExecuteEndToEndTests.groovy | 20 +++- ...rPipelineStageMavenStaticCodeChecks.groovy | 36 ++++-- 3 files changed, 141 insertions(+), 19 deletions(-) diff --git a/resources/com.sap.piper/pipeline/cloudSdkStageDefaults.yml b/resources/com.sap.piper/pipeline/cloudSdkStageDefaults.yml index 3b4120ff1..1f31e35ba 100644 --- a/resources/com.sap.piper/pipeline/cloudSdkStageDefaults.yml +++ b/resources/com.sap.piper/pipeline/cloudSdkStageDefaults.yml @@ -1,4 +1,39 @@ stages: + mavenStaticCodeChecks: + stepConditions: + mavenExecuteStaticCodeChecks: + filePattern: 'pom.xml' + lint: + extensionExists: true + stepConditions: + lint: + filePattern: + - '**/*.js' + - '**/*.jsx' + - '**/*.ts' + - '**/*.tsx' + backendIntegrationTests: + stepConditions: + npmExecuteScripts: + npmScripts: + - 'ci-it-backend' + mavenExecuteIntegration: + filePattern: 'integration-tests/pom.xml' + frontendIntegrationTests: + stepConditions: + npmExecuteScripts: + npmScripts: + - 'ci-it-frontend' + frontendUnitTests: + stepConditions: + frontendUnitTests: + npmScripts: + - 'ci-test' + - 'ci-frontend-unit-test' + npmAudit: + stepConditions: + npmAudit: + filePattern: '**/package.json' endToEndTests: stepConditions: multicloudDeploy: @@ -23,7 +58,48 @@ stages: npmExecuteEndToEndTests: configKeys: - 'appUrls' + performanceTests: + stepConditions: + performanceTests: + configKeys: + - 'cfTargets' + - 'neoTargets' + checkmarxScan: + onlyProductiveBranch: true + stepConditions: + checkmarxScan: + configKeys: + - 'groupId' + sonarQubeScan: + stepConditions: + sonarQubeScan: + configKeys: + - 'projectKey' + - 'instance' + additionalTools: + onlyProductiveBranch: true + extensionExists: true + whitesourceScan: + onlyProductiveBranch: true + stepConditions: + whitesourceScan: + configKeys: + - 'product' + - 'credentialsId' + fortifyScan: + onlyProductiveBranch: true + stepConditions: + fortifyScan: + configKeys: + - 'fortifyCredentialsId' + detectScan: + onlyProductiveBranch: true + stepConditions: + detectScan: + configKeys: + - 'detectTokenCredentialsId' productionDeployment: + onlyProductiveBranch: true stepConditions: multicloudDeploy: configKeys: @@ -36,6 +112,11 @@ stages: neoDeploy: configKeys: - 'neo/account' + tmsUpload: + configKeys: + - 'credentialsId' + - 'mtaPath' + - 'nodeName' healthExecuteCheck: configKeys: - 'testServerUrl' @@ -45,13 +126,20 @@ stages: githubPublishRelease: configKeys: - 'githubTokenCredentialsId' - backendIntegrationTests: + artifactDeployment: + onlyProductiveBranch: true stepConditions: - npmExecuteScripts: - npmScripts: 'ci-it-backend' - mavenExecuteIntegration: - filePattern: 'integration-tests/pom.xml' - frontendIntegrationTests: + artifactDeployment: + configKeys: + - 'nexus' + postPipelineHook: stepConditions: - npmExecuteScripts: - npmScripts: 'ci-it-frontend' + postPipelineHook: + configKeys: + - 'enabled' + archiveReport: + stepConditions: + archiveReport: + filePattern: + - 'mta.yaml' + - 'pom.xml' diff --git a/vars/npmExecuteEndToEndTests.groovy b/vars/npmExecuteEndToEndTests.groovy index a45055642..27a2c4a34 100644 --- a/vars/npmExecuteEndToEndTests.groovy +++ b/vars/npmExecuteEndToEndTests.groovy @@ -11,7 +11,11 @@ import static com.sap.piper.Prerequisites.checkScript @Field Set GENERAL_CONFIG_KEYS = [ /** Executes the deployments in parallel.*/ - 'parallelExecution' + 'parallelExecution', + /** + * The branch used as productive branch, defaults to master. + */ + 'productiveBranch' ] @Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([ /** @@ -31,7 +35,13 @@ import static com.sap.piper.Prerequisites.checkScript /** * Script to be executed from package.json. */ - 'runScript']) + 'runScript', + /** + * Boolean to indicate whether the step should only be executed in the productive branch or not. + * @possibleValues `true`, `false` + */ + 'onlyRunInProductiveBranch' +]) @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS @Field Map CONFIG_KEY_COMPATIBILITY = [parallelExecution: 'features/parallelTestExecution'] @@ -78,6 +88,10 @@ void call(Map parameters = [:]) { error "[${STEP_NAME}] No runScript was defined." } + if (config.onlyRunInProductiveBranch && (config.productiveBranch != env.BRANCH_NAME)) { + return + } + for (int i = 0; i < config.appUrls.size(); i++) { List credentials = [] def appUrl = config.appUrls[i] @@ -117,7 +131,7 @@ void call(Map parameters = [:]) { if (cucumberFiles.size() > 0) { testsPublishResults script: script, cucumber: [active: true, archive: true] - } else if (junitFiles.size() > 0){ + } else if (junitFiles.size() > 0) { testsPublishResults script: script, junit: [active: true, archive: true] } else { echo "[${STEP_NAME}] No JUnit or cucumber report files found, skipping report visualization." diff --git a/vars/piperPipelineStageMavenStaticCodeChecks.groovy b/vars/piperPipelineStageMavenStaticCodeChecks.groovy index cb0cb446e..823111093 100644 --- a/vars/piperPipelineStageMavenStaticCodeChecks.groovy +++ b/vars/piperPipelineStageMavenStaticCodeChecks.groovy @@ -1,7 +1,6 @@ -import com.sap.piper.ConfigurationLoader -import com.sap.piper.GenerateStageDocumentation -import com.sap.piper.QualityCheck -import com.sap.piper.ReportAggregator +import com.sap.piper.ConfigurationHelper +import com.sap.piper.GenerateDocumentation +import com.sap.piper.Utils import static com.sap.piper.Prerequisites.checkScript @@ -9,20 +8,41 @@ import groovy.transform.Field @Field String STEP_NAME = getClass().getName() +@Field STAGE_STEP_KEYS = [ + /** Executes static code checks for Maven based projects. The plugins SpotBugs and PMD are used. */ + 'mavenExecuteStaticCodeChecks' +] @Field Set GENERAL_CONFIG_KEYS = [] -@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS +@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus(STAGE_STEP_KEYS) @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS /** * Execute static code checks for Maven based projects. This stage enforces SAP Cloud SDK specific PND rulesets as well as SpotBugs include filter. * */ -@GenerateStageDocumentation(defaultStageName = 'mavenExecuteStaticCodeChecks') +@GenerateDocumentation void call(Map parameters = [:]) { - String stageName = 'mavenExecuteStaticCodeChecks' final script = checkScript(this, parameters) ?: null + def utils = parameters.juStabUtils ?: new Utils() + + def stageName = parameters.stageName?:env.STAGE_NAME + + Map config = ConfigurationHelper.newInstance(this) + .loadStepDefaults() + .mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS) + .mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS) + .mixin(parameters, PARAMETER_KEYS) + .addIfEmpty('mavenExecuteStaticCodeChecks', script.commonPipelineEnvironment.configuration.runStep?.get(stageName)?.mavenExecuteStaticCodeChecks) + .use() + piperStageWrapper(stageName: stageName, script: script) { - mavenExecuteStaticCodeChecks(script: script) + + // telemetry reporting + utils.pushToSWA([step: STEP_NAME], config) + + if (config.mavenExecuteStaticCodeChecks) { + mavenExecuteStaticCodeChecks(script: script) + } } }