1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-11-06 09:09:19 +02:00

abapEnvironmentPipeline: testBuild Parameter (#4108)

* testBuild Parameter, first try

* add testBuild to general_config_keys

* hard coded stageName

* skip stage publish for testBuild

* add missing import
This commit is contained in:
tiloKo
2022-11-22 11:10:10 +01:00
committed by GitHub
parent 959fa964b1
commit f0cb8c6fc2
6 changed files with 106 additions and 39 deletions

View File

@@ -59,7 +59,6 @@ class AbapEnvironmentPipelineStageBuildTest extends BasePiperTest {
'abapAddonAssemblyKitCreateTargetVector',
'abapAddonAssemblyKitPublishTargetVector'))
assertThat(stepsCalled, not(hasItems('abapEnvironmentCreateTag')))
}
@Test
@@ -80,4 +79,22 @@ class AbapEnvironmentPipelineStageBuildTest extends BasePiperTest {
assertThat(stepsCalled, not(hasItems('cloudFoundryCreateServiceKey')))
}
@Test
void testAbapEnvironmentRunTest4TestBuild() {
nullScript.commonPipelineEnvironment.configuration.runStage = [
'Build': true
]
jsr.step.abapEnvironmentPipelineStageBuild(script: nullScript, testBuild: true, generateTagForAddonComponentVersion: true)
assertThat(stepsCalled, hasItems('cloudFoundryCreateServiceKey',
'abapEnvironmentAssemblePackages',
'abapEnvironmentBuild',
'abapAddonAssemblyKitRegisterPackages',
'abapAddonAssemblyKitCreateTargetVector'))
assertThat(stepsCalled, not(hasItems('abapAddonAssemblyKitReleasePackages',
'abapEnvironmentAssembleConfirm',
'abapAddonAssemblyKitPublishTargetVector',
'abapEnvironmentCreateTag')))
}
}

View File

@@ -97,4 +97,19 @@ class abapEnvironmentPipelineStageIntegrationTestsTest extends BasePiperTest {
assertThat(stepsCalled, hasItems('cloudFoundryDeleteService'))
}
@Test
void testIntegrationTestsTageSkipped4testBuild() {
nullScript.commonPipelineEnvironment.configuration.runStage = [
'Integration Tests': true
]
jsr.step.abapEnvironmentPipelineStageIntegrationTests(script: nullScript, testBuild: true)
assertThat(stepsCalled, not(hasItems('input',
'abapEnvironmentCreateSystem',
'cloudFoundryDeleteService',
'abapEnvironmentBuild',
'cloudFoundryCreateServiceKey')))
}
}

View File

@@ -48,4 +48,11 @@ class abapEnvironmentPipelineStagePublishTest extends BasePiperTest {
assertThat(stepsCalled, hasItem('abapAddonAssemblyKitPublishTargetVector'))
}
@Test
void testPublishSkipped4testBuild() {
nullScript.commonPipelineEnvironment.configuration.runStage = []
jsr.step.abapEnvironmentPipelineStagePublish(script: nullScript, testBuild: true)
assertThat(stepsCalled, not(hasItem('abapAddonAssemblyKitPublishTargetVector')))
}
}

View File

@@ -19,8 +19,8 @@ import static com.sap.piper.Prerequisites.checkScript
'abapEnvironmentAssembleConfirm',
'abapAddonAssemblyKitCreateTargetVector',
'abapAddonAssemblyKitPublishTargetVector',
/** Parameter for host config */
'host',
'host', // Parameter for host config
'testBuild', // Parameter for test execution mode, if true stage will be skipped
'generateTagForAddonProductVersion',
'generateTagForAddonComponentVersion'
]
@@ -41,6 +41,7 @@ void call(Map parameters = [:]) {
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
.mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS)
.mixin(parameters, PARAMETER_KEYS)
.addIfEmpty('testBuild', false)
.use()
piperStageWrapper (script: script, stageName: stageName, stashContent: [], stageLocking: false) {
@@ -50,9 +51,15 @@ void call(Map parameters = [:]) {
abapEnvironmentAssemblePackages script: parameters.script
abapEnvironmentBuild(script: parameters.script, phase: 'GENERATION', downloadAllResultFiles: true, useFieldsOfAddonDescriptor: '[{"use":"Name","renameTo":"SWC"}]')
abapAddonAssemblyKitRegisterPackages script: parameters.script
if (!config.testBuild) { //Skip final steps which can hardly be undone in test mode #1
abapAddonAssemblyKitReleasePackages script: parameters.script
abapEnvironmentAssembleConfirm script: parameters.script
} else {
echo "abapAddonAssemblyKitReleasePackages skipped as testBuild = true"
echo "abapEnvironmentAssembleConfirm skipped as testBuild = true"
}
abapAddonAssemblyKitCreateTargetVector script: parameters.script
if (!config.testBuild) { //Skip final steps which can hardly be undone in test mode #2
abapAddonAssemblyKitPublishTargetVector(script: parameters.script, targetVectorScope: 'T')
if (config.generateTagForAddonComponentVersion || config.generateTagForAddonProductVersion) {
try {
@@ -69,5 +76,9 @@ void call(Map parameters = [:]) {
echo 'Tag creation failed: ' + e.message
}
}
} else {
echo "abapAddonAssemblyKitPublishTargetVector skipped as testBuild = true"
echo "abapEnvironmentCreateTag skipped as testBuild = true"
}
}
}

View File

@@ -13,7 +13,8 @@ import static com.sap.piper.Prerequisites.checkScript
/** If set to true, a confirmation is required to delete the system */
'confirmDeletion',
/** If set to true, the system is never deleted */
'debug'
'debug',
'testBuild' // Parameter for test execution mode, if true stage will be skipped
]
@Field Set STAGE_STEP_KEYS = GENERAL_CONFIG_KEYS
@Field Set STEP_CONFIG_KEYS = STAGE_STEP_KEYS
@@ -32,8 +33,12 @@ void call(Map parameters = [:]) {
.mixin(parameters, PARAMETER_KEYS)
.addIfEmpty('confirmDeletion', true)
.addIfEmpty('debug', false)
.addIfEmpty('testBuild', false)
.use()
if (config.testBuild) {
echo "Stage 'Integration Tests' skipped as parameter 'testBuild' is active"
} else {
piperStageWrapper (script: script, stageName: stageName, stashContent: [], stageLocking: false) {
try {
abapEnvironmentCreateSystem(script: parameters.script, includeAddon: true)
@@ -51,5 +56,6 @@ void call(Map parameters = [:]) {
}
}
}
}
}

View File

@@ -1,12 +1,14 @@
import groovy.transform.Field
import com.sap.piper.Utils
import com.sap.piper.ConfigurationHelper
import static com.sap.piper.Prerequisites.checkScript
@Field String STEP_NAME = getClass().getName()
@Field Set GENERAL_CONFIG_KEYS = []
@Field STAGE_STEP_KEYS = [
'abapEnvironmentAssemblyKitPublishTargetVector'
'abapEnvironmentAssemblyKitPublishTargetVector',
'testBuild' // Parameter for test execution mode, if true stage will be skipped
]
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus(STAGE_STEP_KEYS)
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
@@ -17,10 +19,19 @@ void call(Map parameters = [:]) {
def script = checkScript(this, parameters) ?: this
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('testBuild', false)
.use()
if (config.testBuild) {
echo "Stage 'Publish' skipped as parameter 'testBuild' is active"
} else {
piperStageWrapper (script: script, stageName: stageName, stashContent: [], stageLocking: false) {
abapAddonAssemblyKitPublishTargetVector(script: parameters.script, targetVectorScope: 'P')
}
}
}