From 3f54eb74bcdcfa6fbfb10f6250d67157b584310a Mon Sep 17 00:00:00 2001 From: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> Date: Tue, 3 May 2022 12:52:44 +0200 Subject: [PATCH] ABAPEnvironmentPipeline: move cloudFoundryCreateServiceKey (#3712) * Move cloudFoundryCreateServiceKey * Adapt tests * Update defaults * Fix Unittest * Fix test * Adapt test * Fix * Adapt --- .../pipelines/abapEnvironment/configuration.md | 4 ++-- .../pipelines/abapEnvironment/introduction.md | 4 ++-- .../stages/cloneRepositories.md | 4 ++-- .../abapEnvironment/stages/prepareSystem.md | 14 +------------- .../abapEnvironmentPipelineStageDefaults.yml | 2 +- ...ntPipelineStageCloneRepositoriesTest.groovy | 18 ++++++++++-------- ...onmentPipelineStagePrepareSystemTest.groovy | 2 -- vars/abapEnvironmentPipelineStageATC.groovy | 6 +++++- ...onmentPipelineStageCloneRepositories.groovy | 9 ++++++++- ...nvironmentPipelineStagePrepareSystem.groovy | 1 - 10 files changed, 31 insertions(+), 33 deletions(-) diff --git a/documentation/docs/pipelines/abapEnvironment/configuration.md b/documentation/docs/pipelines/abapEnvironment/configuration.md index 17ec12d5b..dbc970d42 100644 --- a/documentation/docs/pipelines/abapEnvironment/configuration.md +++ b/documentation/docs/pipelines/abapEnvironment/configuration.md @@ -9,8 +9,8 @@ You can have a look at different pipeline configurations in our [SAP-samples rep |--------------------------|-------| | Init | - | | [Initial Checks](stages/initialChecks.md) | [abapAddonAssemblyKitCheckPV](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitCheckPV/), [abapAddonAssemblyKitCheckCVs](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitCheckCVs/), [abapAddonAssemblyKitReserveNextPackages](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitReserveNextPackages/),| -| [Prepare System](stages/prepareSystem.md) | [abapEnvironmentCreateSystem](https://sap.github.io/jenkins-library/steps/abapEnvironmentCreateSystem/), [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/)| -| [Clone Repositories](stages/cloneRepositories.md) | [abapEnvironmentPullGitRepo](https://sap.github.io/jenkins-library/steps/abapEnvironmentPullGitRepo/), [abapEnvironmentCloneGitRepo](https://sap.github.io/jenkins-library/steps/abapEnvironmentCloneGitRepo/), [abapEnvironmentCheckoutBranch](https://sap.github.io/jenkins-library/steps/abapEnvironmentCheckoutBranch/)| +| [Prepare System](stages/prepareSystem.md) | [abapEnvironmentCreateSystem](https://sap.github.io/jenkins-library/steps/abapEnvironmentCreateSystem/) | +| [Clone Repositories](stages/cloneRepositories.md) | [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/), [abapEnvironmentPullGitRepo](https://sap.github.io/jenkins-library/steps/abapEnvironmentPullGitRepo/), [abapEnvironmentCloneGitRepo](https://sap.github.io/jenkins-library/steps/abapEnvironmentCloneGitRepo/), [abapEnvironmentCheckoutBranch](https://sap.github.io/jenkins-library/steps/abapEnvironmentCheckoutBranch/)| | [Test](stages/test.md) | [abapEnvironmentRunATCCheck](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunATCCheck/), [abapEnvironmentRunAUnitTest](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunAUnitTest/), [abapEnvironmentPushATCSystemConfig](https://sap.github.io/jenkins-library/steps/abapEnvironmentPushATCSystemConfig/)| | [Build](stages/build.md) | [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/), [abapEnvironmentAssemblePackages](https://sap.github.io/jenkins-library/steps/abapEnvironmentAssemblePackages/), [abapAddonAssemblyKitRegisterPackages](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitRegisterPackages/), [abapAddonAssemblyKitReleasePackages](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitReleasePackages/), [abapEnvironmentAssembleConfirm](https://sap.github.io/jenkins-library/steps/abapEnvironmentAssembleConfirm/), [abapAddonAssemblyKitCreateTargetVector](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitCreateTargetVector/), [abapAddonAssemblyKitPublishTargetVector](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitPublishTargetVector/)| | [Integration Tests](stages/integrationTest.md) | [abapEnvironmentCreateSystem](https://sap.github.io/jenkins-library/steps/abapEnvironmentCreateSystem/), [cloudFoundryDeleteService](https://sap.github.io/jenkins-library/steps/cloudFoundryDeleteService/)| diff --git a/documentation/docs/pipelines/abapEnvironment/introduction.md b/documentation/docs/pipelines/abapEnvironment/introduction.md index eb10aab87..4d4408b50 100644 --- a/documentation/docs/pipelines/abapEnvironment/introduction.md +++ b/documentation/docs/pipelines/abapEnvironment/introduction.md @@ -25,8 +25,8 @@ The following stages and steps are part of the pipeline: |--------------------------|-------| | Init | - | | [Initial Checks](stages/initialChecks.md) | [abapAddonAssemblyKitCheckPV](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitCheckPV/), [abapAddonAssemblyKitCheckCVs](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitCheckCVs/)| -| [Prepare System](stages/prepareSystem.md) | [abapEnvironmentCreateSystem](https://sap.github.io/jenkins-library/steps/abapEnvironmentCreateSystem/), [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/)| -| [Clone Repositories](stages/cloneRepositories.md) | [abapEnvironmentPullGitRepo](https://sap.github.io/jenkins-library/steps/abapEnvironmentPullGitRepo/)| +| [Prepare System](stages/prepareSystem.md) | [abapEnvironmentCreateSystem](https://sap.github.io/jenkins-library/steps/abapEnvironmentCreateSystem/) | +| [Clone Repositories](stages/cloneRepositories.md) | [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/), [abapEnvironmentPullGitRepo](https://sap.github.io/jenkins-library/steps/abapEnvironmentPullGitRepo/)| | [Test](stages/test.md) | [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/), [abapEnvironmentRunATCCheck](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunATCCheck/), [abapEnvironmentRunAUnitTest](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunAUnitTest/) | | [Build](stages/build.md) | [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/), [abapAddonAssemblyKitReserveNextPackages](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitReserveNextPackages/), [abapEnvironmentAssemblePackages](https://sap.github.io/jenkins-library/steps/abapEnvironmentAssemblePackages/), [abapAddonAssemblyKitRegisterPackages](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitRegisterPackages/), [abapEnvironmentAssembleConfirm](https://sap.github.io/jenkins-library/steps/abapEnvironmentAssembleConfirm/), [abapAddonAssemblyKitReleasePackages](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitReleasePackages/), [abapAddonAssemblyKitCreateTargetVector](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitCreateTargetVector/), [abapAddonAssemblyKitPublishTargetVector](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitPublishTargetVector/)| | [Integration Tests](stages/integrationTest.md) | [cloudFoundryCreateService](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateService/)| diff --git a/documentation/docs/pipelines/abapEnvironment/stages/cloneRepositories.md b/documentation/docs/pipelines/abapEnvironment/stages/cloneRepositories.md index 96f4ea9ee..b7fc250b1 100644 --- a/documentation/docs/pipelines/abapEnvironment/stages/cloneRepositories.md +++ b/documentation/docs/pipelines/abapEnvironment/stages/cloneRepositories.md @@ -1,11 +1,12 @@ # Clone Repositories -This stage creates pulls/clones the specified software components (repositories) to the SAP BTP, ABAP environment system. +This stage creates pulls/clones the specified software components (repositories) to the SAP BTP, ABAP environment system. As a prerequisite, the Communication Arrangement [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html) (SAP BTP, ABAP Environment - Software Component Test Integration) is created using the step `cloudFoundryCreateServiceKey`. With the creation of the Communication Arrangement, a User and Password is created on the SAP BTP, ABAP environment system for the APIs that are used in this stage, as well as in the ATC stage. ## Steps The following steps can be executed in this stage: +- [cloudFoundryCreateServiceKey](../../../steps/cloudFoundryCreateServiceKey.md) - [abapEnvironmentPullGitRepo](../../../steps/abapEnvironmentPullGitRepo.md) - [abapEnvironmentCloneGitRepo](../../../steps/abapEnvironmentCloneGitRepo.md) - [abapEnvironmentCheckoutBranch](../../../steps/abapEnvironmentCheckoutBranch.md) @@ -37,7 +38,6 @@ general: cfSpace: 'mySpace' cfCredentialsId: 'cfAuthentification' cfServiceInstance: 'abap_system' - cfServiceKeyName: 'JENKINS_SAP_COM_0510' stages: Clone Repositories: repositories: 'repositories.yml' diff --git a/documentation/docs/pipelines/abapEnvironment/stages/prepareSystem.md b/documentation/docs/pipelines/abapEnvironment/stages/prepareSystem.md index a469212b4..7dfbeeb0b 100644 --- a/documentation/docs/pipelines/abapEnvironment/stages/prepareSystem.md +++ b/documentation/docs/pipelines/abapEnvironment/stages/prepareSystem.md @@ -1,13 +1,12 @@ # Prepare System -In this stage, the SAP BTP, ABAP environment system is created. This is done with the `abapEnvironmentCreateSystem` step. After the system creation, the Communication Arrangement [SAP_COM_0510](https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html) (SAP BTP, ABAP Environment - Software Component Test Integration) is created using the step `cloudFoundryCreateServiceKey`. With the creation of the Communication Arrangement, a User and Password is created on the SAP BTP, ABAP environment system for the APIs that are used in the following stages. +In this stage, the SAP BTP, ABAP environment system is created. This is done with the `abapEnvironmentCreateSystem` step. ## Steps The following steps are executed in this stage: - [abapEnvironmentCreateSystem](../../../steps/abapEnvironmentCreateSystem.md) -- [cloudFoundryCreateServiceKey](../../../steps/cloudFoundryCreateServiceKey.md) ## Stage Parameters @@ -28,7 +27,6 @@ general: cfSpace: 'mySpace' cfCredentialsId: 'cfAuthentification' cfServiceInstance: 'abap_system' - cfServiceKeyName: 'JENKINS_SAP_COM_0510' stages: Prepare System: cfService: 'abap' @@ -39,14 +37,4 @@ stages: abapSystemID: 'H02' abapSystemSizeOfPersistence: 4 abapSystemSizeOfRuntime: 1 - cfServiceKeyConfig: 'serviceKey.json' -``` - -### serviceKey.json - -```json -{ - "scenario_id": "SAP_COM_0510", - "type": "basic" -} ``` diff --git a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStageDefaults.yml b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStageDefaults.yml index 7abc8d7ed..e622b1b63 100644 --- a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStageDefaults.yml +++ b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStageDefaults.yml @@ -13,10 +13,10 @@ stages: abapSystemSizeOfPersistence: 4 abapSystemSizeOfRuntime: 1 cfServiceKeyName: 'sap_com_0510' - cfServiceKeyConfig: '{"scenario_id":"SAP_COM_0510","type":"basic"}' 'Clone Repositories': cfServiceKeyName: 'sap_com_0510' + cfServiceKeyConfig: '{"scenario_id":"SAP_COM_0510","type":"basic"}' ordinal: 30 'ATC': diff --git a/test/groovy/templates/AbapEnvironmentPipelineStageCloneRepositoriesTest.groovy b/test/groovy/templates/AbapEnvironmentPipelineStageCloneRepositoriesTest.groovy index 76fb6632b..2c1cf586a 100644 --- a/test/groovy/templates/AbapEnvironmentPipelineStageCloneRepositoriesTest.groovy +++ b/test/groovy/templates/AbapEnvironmentPipelineStageCloneRepositoriesTest.groovy @@ -23,7 +23,6 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { .around(jsr) private stepsCalled = [] - @Before void init() { binding.variables.env.STAGE_NAME = 'Clone Repositories' @@ -35,18 +34,21 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { helper.registerAllowedMethod('strategy', [Map], {m -> stepsCalled.add('strategy') }) + helper.registerAllowedMethod('cloudFoundryCreateServiceKey', [Map.class], {m -> stepsCalled.add('cloudFoundryCreateServiceKey')}) helper.registerAllowedMethod('abapEnvironmentPullGitRepo', [Map.class], {m -> stepsCalled.add('abapEnvironmentPullGitRepo')}) helper.registerAllowedMethod('abapEnvironmentCheckoutBranch', [Map.class], {m -> stepsCalled.add('abapEnvironmentCheckoutBranch')}) helper.registerAllowedMethod('abapEnvironmentCloneGitRepo', [Map.class], {m -> stepsCalled.add('abapEnvironmentCloneGitRepo')}) + // assertThat(stepsCalled, hasItem('cloudFoundryCreateServiceKey')) } @Test void testAbapEnvironmentPipelineStageCloneRepositoriesPull() { nullScript.commonPipelineEnvironment.configuration.runStage = [] - jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'Pull') + jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'Pull', host: 'abc.com') assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo')) + assertThat(stepsCalled, not(hasItem('cloudFoundryCreateServiceKey'))) assertThat(stepsCalled, not(hasItems('abapEnvironmentCloneGitRepo'))) assertThat(stepsCalled, not(hasItems('abapEnvironmentCheckoutBranch'))) } @@ -57,7 +59,7 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { nullScript.commonPipelineEnvironment.configuration.runStage = [] jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'Clone') - assertThat(stepsCalled, hasItems('abapEnvironmentCloneGitRepo')) + assertThat(stepsCalled, hasItems('abapEnvironmentCloneGitRepo', 'cloudFoundryCreateServiceKey')) assertThat(stepsCalled, not(hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch'))) } @@ -67,7 +69,7 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { nullScript.commonPipelineEnvironment.configuration.runStage = [] jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'CheckoutPull') - assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch')) + assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch', 'cloudFoundryCreateServiceKey')) assertThat(stepsCalled, not(hasItems('abapEnvironmentCloneGitRepo'))) } @@ -75,9 +77,9 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { void testAbapEnvironmentPipelineStageCloneRepositoriesPullCheckoutPull() { nullScript.commonPipelineEnvironment.configuration.runStage = [] - jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'AddonBuild') + jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'AddonBuild', host: 'abc.com') - assertThat(stepsCalled, not(hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch'))) + assertThat(stepsCalled, not(hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch', 'cloudFoundryCreateServiceKey'))) assertThat(stepsCalled, hasItems('abapEnvironmentCloneGitRepo')) } @@ -85,9 +87,9 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { void testAbapEnvironmentPipelineStageCloneRepositoriesNoStrategy() { nullScript.commonPipelineEnvironment.configuration.runStage = [] - jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript) + jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, host: 'abc.com') assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo')) - assertThat(stepsCalled, not(hasItems('abapEnvironmentCloneGitRepo', 'abapEnvironmentCheckoutBranch'))) + assertThat(stepsCalled, not(hasItems('abapEnvironmentCloneGitRepo', 'abapEnvironmentCheckoutBranch', 'cloudFoundryCreateServiceKey'))) } } diff --git a/test/groovy/templates/AbapEnvironmentPipelineStagePrepareSystemTest.groovy b/test/groovy/templates/AbapEnvironmentPipelineStagePrepareSystemTest.groovy index 86dbb9c04..a50660a37 100644 --- a/test/groovy/templates/AbapEnvironmentPipelineStagePrepareSystemTest.groovy +++ b/test/groovy/templates/AbapEnvironmentPipelineStagePrepareSystemTest.groovy @@ -37,7 +37,6 @@ class AbapEnvironmentPipelineStagePrepareSystemTest extends BasePiperTest { return null }) helper.registerAllowedMethod('abapEnvironmentCreateSystem', [Map.class], {m -> stepsCalled.add('abapEnvironmentCreateSystem')}) - helper.registerAllowedMethod('cloudFoundryCreateServiceKey', [Map.class], {m -> stepsCalled.add('cloudFoundryCreateServiceKey')}) } @Test @@ -49,6 +48,5 @@ class AbapEnvironmentPipelineStagePrepareSystemTest extends BasePiperTest { jsr.step.abapEnvironmentPipelineStagePrepareSystem(script: nullScript) assertThat(stepsCalled, hasItem('abapEnvironmentCreateSystem')) - assertThat(stepsCalled, hasItem('cloudFoundryCreateServiceKey')) } } diff --git a/vars/abapEnvironmentPipelineStageATC.groovy b/vars/abapEnvironmentPipelineStageATC.groovy index 4d249a719..b12da64b2 100644 --- a/vars/abapEnvironmentPipelineStageATC.groovy +++ b/vars/abapEnvironmentPipelineStageATC.groovy @@ -11,12 +11,16 @@ import static com.sap.piper.Prerequisites.checkScript @Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = [] @Field STAGE_STEP_KEYS = [ + /** Creates Communication Arrangements for ABAP Environment instance via the cloud foundry command line interface */ + 'cloudFoundryCreateServiceKey', /** Starts an ATC check run on the ABAP Environment instance */ 'abapEnvironmentRunATCCheck', /** Creates/Updates ATC System Configuration */ 'abapEnvironmentPushATCSystemConfig', /** Parameter for ATC System Configuration json */ - 'atcSystemConfigFilePath' + 'atcSystemConfigFilePath', + /** Parameter for host config */ + 'host' ] @Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus(STAGE_STEP_KEYS) @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS diff --git a/vars/abapEnvironmentPipelineStageCloneRepositories.groovy b/vars/abapEnvironmentPipelineStageCloneRepositories.groovy index 2b0fc6916..1e0c2af45 100644 --- a/vars/abapEnvironmentPipelineStageCloneRepositories.groovy +++ b/vars/abapEnvironmentPipelineStageCloneRepositories.groovy @@ -7,6 +7,8 @@ import static com.sap.piper.Prerequisites.checkScript @Field String STEP_NAME = getClass().getName() @Field Set GENERAL_CONFIG_KEYS = [] @Field STAGE_STEP_KEYS = [ + /** Creates Communication Arrangements for ABAP Environment instance via the cloud foundry command line interface */ + 'cloudFoundryCreateServiceKey', /** Pulls Software Components / Git repositories into the ABAP Environment instance */ 'abapEnvironmentPullGitRepo', /** Checks out a Branch in the pulled Software Component on the ABAP Environment instance */ @@ -14,7 +16,9 @@ import static com.sap.piper.Prerequisites.checkScript /** Clones Software Components / Git repositories into the ABAP Environment instance and checks out the respective branches */ 'abapEnvironmentCloneGitRepo', /** Specifies the strategy that should be peformed on the ABAP Environment instance*/ - 'strategy' + 'strategy', + /** Parameter for host config */ + 'host' ] @Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus(STAGE_STEP_KEYS) @Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS @@ -34,6 +38,9 @@ void call(Map parameters = [:]) { .use() piperStageWrapper (script: script, stageName: stageName, stashContent: [], stageLocking: false) { + if (!config.host) { + cloudFoundryCreateServiceKey script: parameters.script + } switch (config.strategy) { case 'Pull': abapEnvironmentPullGitRepo script: parameters.script diff --git a/vars/abapEnvironmentPipelineStagePrepareSystem.groovy b/vars/abapEnvironmentPipelineStagePrepareSystem.groovy index d958486c4..b15112f65 100644 --- a/vars/abapEnvironmentPipelineStagePrepareSystem.groovy +++ b/vars/abapEnvironmentPipelineStagePrepareSystem.groovy @@ -22,7 +22,6 @@ void call(Map parameters = [:]) { piperStageWrapper (script: script, stageName: stageName, stashContent: [], stageLocking: false) { abapEnvironmentCreateSystem script: parameters.script - cloudFoundryCreateServiceKey script: parameters.script } }