1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00

Abap pipeline build stage skip create service key (#3832)

* CreateServiceKey only if host was not configured
This commit is contained in:
tiloKo 2022-06-15 14:57:28 +02:00 committed by GitHub
parent d28a48896c
commit be5e850eab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 101 additions and 3 deletions

View File

@ -0,0 +1,79 @@
package templates
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import util.BasePiperTest
import util.JenkinsReadYamlRule
import util.JenkinsStepRule
import util.PipelineWhenException
import util.Rules
import static org.hamcrest.Matchers.*
import static org.junit.Assert.assertThat
class AbapEnvironmentPipelineStageBuildTest extends BasePiperTest {
private JenkinsStepRule jsr = new JenkinsStepRule(this)
@Rule
public RuleChain rules = Rules
.getCommonRules(this)
.around(new JenkinsReadYamlRule(this))
.around(jsr)
private stepsCalled = []
@Before
void init() {
binding.variables.env.STAGE_NAME = 'Build'
helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body ->
assertThat(m.stageName, is('Build'))
return body()
})
helper.registerAllowedMethod('cloudFoundryCreateServiceKey', [Map.class], {m -> stepsCalled.add('cloudFoundryCreateServiceKey')})
helper.registerAllowedMethod('abapEnvironmentAssemblePackages', [Map.class], {m -> stepsCalled.add('abapEnvironmentAssemblePackages')})
helper.registerAllowedMethod('abapEnvironmentBuild', [Map.class], {m -> stepsCalled.add('abapEnvironmentBuild')})
helper.registerAllowedMethod('abapAddonAssemblyKitRegisterPackages', [Map.class], {m -> stepsCalled.add('abapAddonAssemblyKitRegisterPackages')})
helper.registerAllowedMethod('abapAddonAssemblyKitReleasePackages', [Map.class], {m -> stepsCalled.add('abapAddonAssemblyKitReleasePackages')})
helper.registerAllowedMethod('abapEnvironmentAssembleConfirm', [Map.class], {m -> stepsCalled.add('abapEnvironmentAssembleConfirm')})
helper.registerAllowedMethod('abapAddonAssemblyKitCreateTargetVector', [Map.class], {m -> stepsCalled.add('abapAddonAssemblyKitCreateTargetVector')})
helper.registerAllowedMethod('abapAddonAssemblyKitPublishTargetVector', [Map.class], {m -> stepsCalled.add('abapAddonAssemblyKitPublishTargetVector')})
}
@Test
void testAbapEnvironmentRunTestsWithoutHost() {
nullScript.commonPipelineEnvironment.configuration.runStage = [
'Build': true
]
jsr.step.abapEnvironmentPipelineStageBuild(script: nullScript)
assertThat(stepsCalled, hasItems('cloudFoundryCreateServiceKey',
'abapEnvironmentAssemblePackages',
'abapEnvironmentBuild',
'abapAddonAssemblyKitRegisterPackages',
'abapAddonAssemblyKitReleasePackages',
'abapEnvironmentAssembleConfirm',
'abapAddonAssemblyKitCreateTargetVector',
'abapAddonAssemblyKitPublishTargetVector'))
}
@Test
void testAbapEnvironmentRunTestsWithHost() {
nullScript.commonPipelineEnvironment.configuration.runStage = [
'Build': true
]
jsr.step.abapEnvironmentPipelineStageBuild(script: nullScript, host: 'abc.com')
assertThat(stepsCalled, hasItems('abapEnvironmentAssemblePackages',
'abapEnvironmentBuild',
'abapAddonAssemblyKitRegisterPackages',
'abapAddonAssemblyKitReleasePackages',
'abapEnvironmentAssembleConfirm',
'abapAddonAssemblyKitCreateTargetVector',
'abapAddonAssemblyKitPublishTargetVector'))
assertThat(stepsCalled, not(hasItems('cloudFoundryCreateServiceKey')))
}
}

View File

@ -1,5 +1,10 @@
import groovy.transform.Field
import com.cloudbees.groovy.cps.NonCPS
import com.sap.piper.GenerateStageDocumentation
import groovy.transform.Field
import com.sap.piper.Utils
import com.sap.piper.ConfigurationHelper
import com.sap.piper.ConfigurationLoader
import static com.sap.piper.Prerequisites.checkScript
@ -7,13 +12,15 @@ import static com.sap.piper.Prerequisites.checkScript
@Field Set GENERAL_CONFIG_KEYS = []
@Field STAGE_STEP_KEYS = [
'cloudFoundryCreateServiceKey',
'abapAddonAssemblyKitReserveNextPackages',
'abapEnvironmentAssemblePackages',
'abapEnvironmentBuild',
'abapAddonAssemblyKitRegisterPackages',
'abapAddonAssemblyKitReleasePackages',
'abapEnvironmentAssembleConfirm',
'abapAddonAssemblyKitCreateTargetVector',
'abapAddonAssemblyKitPublishTargetVector'
'abapAddonAssemblyKitPublishTargetVector',
/** Parameter for host config */
'host'
]
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus(STAGE_STEP_KEYS)
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
@ -24,8 +31,20 @@ void call(Map parameters = [:]) {
def script = checkScript(this, parameters) ?: this
def stageName = parameters.stageName?:env.STAGE_NAME
// load default & individual configuration
Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults([:], stageName)
.mixin(ConfigurationLoader.defaultStageConfiguration(script, stageName))
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
.mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS)
.mixin(parameters, PARAMETER_KEYS)
.use()
piperStageWrapper (script: script, stageName: stageName, stashContent: [], stageLocking: false) {
if (!config.host) {
cloudFoundryCreateServiceKey script: parameters.script
}
abapEnvironmentAssemblePackages script: parameters.script
abapEnvironmentBuild(script: parameters.script, phase: 'GENERATION', downloadAllResultFiles: true, useFieldsOfAddonDescriptor: '[{"use":"Name","renameTo":"SWC"}]')
abapAddonAssemblyKitRegisterPackages script: parameters.script