From f67cbbe0a7531769873f63e67fd318b6ccea8691 Mon Sep 17 00:00:00 2001 From: Dominik Lendle <59923031+dominiklendle@users.noreply.github.com> Date: Thu, 11 Nov 2021 15:10:14 +0100 Subject: [PATCH] A unit step integration (#3120) * Add AUnit stage * Add AUnit stage to ABAP Pipeline * Add Groovy Tests * surround header with space line * correct class name * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * adapt Pipeline Tests * Update tests & docu * adapt tests * Fix Pipeline Tests * adapt tests * Adapt tests * Adapt tests * docu fixes * Adapt tests * Improve Tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt host config * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * Adapt tests * adapt docu links * adapt docu links * adapt docu links * adapt docu links * Add example to config docu * change docu * Change host check * Adapt tests * Add Prepare System defaults * Change Prepare System defaults * return after writing xml results * change logging * return after results have been persisted * Change host check * echo test * echo test * echo test * echo test * echo test * config host checker working * Enable host groovy test * remove duplicates * docu extension AUnit extension stage * Remove trailing spaces * package restrictions added to docu * correct to type * correct type aunit tests * add capital letters to docu examples * remove escape * adapt unit tests Co-authored-by: Daniel Mieg Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> --- cmd/abapEnvironmentRunAUnitTest.go | 2 +- cmd/abapEnvironmentRunAUnitTest_generated.go | 2 +- cmd/abapEnvironmentRunAUnitTest_test.go | 20 +-- .../abapEnvironment/configuration.md | 4 +- .../abapEnvironment/extensibility.md | 41 +++++- .../pipelines/abapEnvironment/introduction.md | 4 +- .../pipelines/abapEnvironment/stages/ATC.md | 64 --------- .../pipelines/abapEnvironment/stages/Test.md | 134 ++++++++++++++++++ .../docs/scenarios/abapEnvironmentAddons.md | 1 + .../docs/scenarios/abapEnvironmentTest.md | 8 ++ .../docs/steps/abapEnvironmentRunAUnitTest.md | 16 +-- documentation/mkdocs.yml | 3 +- .../abapEnvironmentPipelineStageDefaults.yml | 21 ++- .../abapEnvironmentPipelineStages.yml | 3 +- .../abapEnvironmentPipelineStashSettings.yml | 7 +- .../metadata/abapEnvironmentRunAUnitTest.yaml | 2 +- ...AbapEnvironmentPipelineStageATCTest.groovy | 46 ++++++ ...apEnvironmentPipelineStageAUnitTest.groovy | 60 ++++++++ ...tPipelineStageCloneRepositoriesTest.groovy | 24 +--- .../AbapEnvironmentPipelineTest.groovy | 52 ++++++- vars/abapEnvironmentPipeline.groovy | 20 ++- vars/abapEnvironmentPipelineStageAUnit.groovy | 41 ++++++ 22 files changed, 436 insertions(+), 139 deletions(-) delete mode 100644 documentation/docs/pipelines/abapEnvironment/stages/ATC.md create mode 100644 documentation/docs/pipelines/abapEnvironment/stages/Test.md create mode 100644 test/groovy/templates/AbapEnvironmentPipelineStageATCTest.groovy create mode 100644 test/groovy/templates/AbapEnvironmentPipelineStageAUnitTest.groovy create mode 100644 vars/abapEnvironmentPipelineStageAUnit.groovy diff --git a/cmd/abapEnvironmentRunAUnitTest.go b/cmd/abapEnvironmentRunAUnitTest.go index c389aebf7..95520c97e 100644 --- a/cmd/abapEnvironmentRunAUnitTest.go +++ b/cmd/abapEnvironmentRunAUnitTest.go @@ -274,7 +274,7 @@ func buildAUnitObjectSetString(AUnitConfig AUnitConfig) (objectSetString string) objectSetString += `` } for _, flatObjectSet := range t.FlatObjectSet { - objectSetString += `` + objectSetString += `` } objectSetString += `` } diff --git a/cmd/abapEnvironmentRunAUnitTest_generated.go b/cmd/abapEnvironmentRunAUnitTest_generated.go index 0c21912e3..a06cf61df 100644 --- a/cmd/abapEnvironmentRunAUnitTest_generated.go +++ b/cmd/abapEnvironmentRunAUnitTest_generated.go @@ -229,7 +229,7 @@ func abapEnvironmentRunAUnitTestMetadata() config.StepData { Type: "secret", }, }, - Scope: []string{"PARAMETERS", "STAGES", "STEPS2"}, + Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, Type: "string", Mandatory: true, Aliases: []config.Alias{}, diff --git a/cmd/abapEnvironmentRunAUnitTest_test.go b/cmd/abapEnvironmentRunAUnitTest_test.go index dc86a42d4..a78291d36 100644 --- a/cmd/abapEnvironmentRunAUnitTest_test.go +++ b/cmd/abapEnvironmentRunAUnitTest_test.go @@ -53,7 +53,7 @@ func TestBuildAUnitTestBody(t *testing.T) { expectedmetadataString := `` expectedoptionsString := `` - expectedobjectSetString := `` + expectedobjectSetString := `` var err error var config AUnitConfig @@ -307,24 +307,6 @@ func TestGetResultAUnitRun(t *testing.T) { func TestRunAbapEnvironmentRunAUnitTest(t *testing.T) { t.Parallel() - t.Run("happy path", func(t *testing.T) { - t.Parallel() - /* - t.Parallel() - // init - config := abapEnvironmentRunAUnitTestOptions{} - - utils := newAbapEnvironmentRunAUnitTestTestsUtils() - utils.AddFile("file.txt", []byte("dummy content")) - - // test - err := runAbapEnvironmentRunAUnitTest(&config, nil, nil, utils) - - // assert - assert.NoError(t, err) - */ - }) - t.Run("FetchXcsrfToken Test", func(t *testing.T) { t.Parallel() diff --git a/documentation/docs/pipelines/abapEnvironment/configuration.md b/documentation/docs/pipelines/abapEnvironment/configuration.md index e52a9f3f6..ba303482e 100644 --- a/documentation/docs/pipelines/abapEnvironment/configuration.md +++ b/documentation/docs/pipelines/abapEnvironment/configuration.md @@ -11,8 +11,8 @@ You can have a look at different pipeline configurations in our [SAP-samples rep | [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/)| -| [ATC](stages/ATC.md) | [abapEnvironmentRunATCCheck](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunATCCheck/)| -| [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/), [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/)| +| [Test](stages/Test.md) | [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/)| | [Confirm](stages/confirm.md) | - | | [Publish](stages/publish.md) | [abapAddonAssemblyKitPublishTargetVector](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitPublishTargetVector/)| diff --git a/documentation/docs/pipelines/abapEnvironment/extensibility.md b/documentation/docs/pipelines/abapEnvironment/extensibility.md index cc243db1d..96736c854 100644 --- a/documentation/docs/pipelines/abapEnvironment/extensibility.md +++ b/documentation/docs/pipelines/abapEnvironment/extensibility.md @@ -34,11 +34,11 @@ While `tools: [checkStyle(pattern: '**/**/ATCResults.xml')]` will display the AT !!! caution "Local Jenkins" If you are using a local Jenkins you may have to [adapt the Jenkins URL](https://stackoverflow.com/a/39543223) in the configuration if the CheckStyle Plugin shows this error: "Can't create fingerprints for some files". -## 2. Extend the ATC stage to send ATC Results via E-Mail +## 2. Extend the ATC stage to send ATC results via E-Mail In general when executing the `ATC` stage, the respective ATC results will normally be pinned to the Jenkins Job in a checkStyle XML format. Additionally, you can set the `generateHTML` flag to `true` for the `abapEnvironmentRunATCCheck` step. This includes the generation of an HTML document containing the ATC results for the `abapEnvironmentRunATCCheck` step that will also be pinned to the respective Jenkins Job. -The ATC Results can be attached to an E-Mail or being sent as the E-Mail body with the [Email Extension Plugin](https://www.jenkins.io/doc/pipeline/steps/email-ext/) ([GitHub Project](https://github.com/jenkinsci/email-ext-plugin)) using the `emailext()` method. Make sure that you have configured the Email Extension Plugin correctly before using it. +The ATC results can be attached to an E-Mail or being sent as the E-Mail body with the [Email Extension Plugin](https://www.jenkins.io/doc/pipeline/steps/email-ext/) ([GitHub Project](https://github.com/jenkinsci/email-ext-plugin)) using the `emailext()` method. Make sure that you have configured the Email Extension Plugin correctly before using it. In the following example we only provide a sample configuration using the Jenkins [Email Extension Plugin](https://www.jenkins.io/doc/pipeline/steps/email-ext/). The E-Mail can be fully customized to your needs. Please refer to the Email Extension Plugin Documentation to see the full list of parameter that are supported. If you haven't created it already, create/extend the file `.pipeline/extensions/ATC.groovy` with the following content: @@ -55,10 +55,10 @@ void call(Map params) { params.originalStage() emailext ( - attachmentsPattern: 'ATCResults.html', //This will attach the ATC Results to the E-Mail + attachmentsPattern: 'ATCResults.html', //This will attach the ATC results to the E-Mail to: 'user@example.com, admin@example.com', - subject: "ATC Results Mail from latest Run in System H01", - body: 'Dear User, here are the results from the latest ATC run ${env.BUILD_ID}.' + readFile('ATCResults.html') //This will parse the ATC Results and send it as the E-Mail body + subject: "ATC results Mail from latest Run in System H01", + body: 'Dear User, here are the results from the latest ATC run ${env.BUILD_ID}.' + readFile('ATCResults.html') //This will parse the ATC results and send it as the E-Mail body ) echo "End - Extension for stage: ${params.stageName}" @@ -66,6 +66,35 @@ void call(Map params) { return this ``` -Note that in above example the ATC Results, stored in the `ATCResults.html` file that is pinned to the Jenkins Job, will be sent as an attachmend using the `attachmentsPattern` parameter as well as being parsed and attached to the E-Mail body using the `body` parameter. Both methods are possible. If you chose to include the ATC Results in the E-Mail body make sure to read the file content properly, e.g. using the `readFile()` method. +Note that in above example the ATC results, stored in the `ATCResults.html` file that is pinned to the Jenkins Job, will be sent as an attachmend using the `attachmentsPattern` parameter as well as being parsed and attached to the E-Mail body using the `body` parameter. Both methods are possible. If you chose to include the ATC results in the E-Mail body make sure to read the file content properly, e.g. using the `readFile()` method. The `subject` parameter defines the subject of the E-Mail that will be sent. The `to` parameter specifies a list of recipients separated by a comma. You can also set a Distribution Lists as a recipient. For all parameters it is also possible to use Jenkins environment variables like `${env.BUILD_ID}` or `${env.JENKINS_URL}`. + +## 3. Extend the AUnit stage via the JUnit Plugin + +The `AUnit` stage will execute AUnit test runs on a SAP BTP ABAP environment system via the step [abapEnvironmentRunAUnitTest](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunAUnitTest/). +These results will be pinned to the respective Jenkins Jobs as an XML file in the JUnit format. Per default this file will be named `AUnitResults.xml`. You can change the file name via the step parameter `aUnitResultsFileName`. +Jenkins offers the possibility to display the AUnit results utilizing the JUnit format with the [JUnit Plugin](https://plugins.jenkins.io/junit/) ([GitHub Project](https://github.com/jenkinsci/junit-plugin)). + +To achieve this, create a file `.pipeline/extensions/AUnit.groovy` with the following content: + +```groovy +void call(Map params) { + //access stage name + echo "Start - Extension for stage: ${params.stageName}" + + //access config + echo "Current stage config: ${params.config}" + + //execute original stage as defined in the template + params.originalStage() + + junit skipPublishingChecks: true, allowEmptyResults: true, testResults: '**/AUnitResults.xml' + + echo "End - Extension for stage: ${params.stageName}" +} +return this +``` + +You can simply use the JUnit Plugin for Jenkins in the AUnit stage within the `.pipeline/extensions/AUnit.groovy` file by using the `junit` command. You can set optional parameters like `skipPublishingChecks: true` in order to disable an integration to the GitHub Checks API. `allowEmptyResults: true` allows the build status of the Jenkins run to be `SUCCESS` even if there have been no results from the respective AUnit test run in the test results file. Vice versa, `allowEmptyResults: false` will set the build status to `FAILURE` if the test results file contains no results. +The `testResults` parameter specifies the path to the AUnit test results file which has been saved and pinned to the Jenkins job in the `abapEnvironmentRunAUnitTest` step. Please refer to the documentation of the ([JUnit Plugin](https://plugins.jenkins.io/junit/#documentation)) for more detailled information on the usage and configuration of the JUnit plugin parameters. diff --git a/documentation/docs/pipelines/abapEnvironment/introduction.md b/documentation/docs/pipelines/abapEnvironment/introduction.md index b60946d8a..46e32a819 100644 --- a/documentation/docs/pipelines/abapEnvironment/introduction.md +++ b/documentation/docs/pipelines/abapEnvironment/introduction.md @@ -27,8 +27,8 @@ The following stages and steps are part of the pipeline: | [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/)| -| [ATC](stages/ATC.md) | [abapEnvironmentRunATCCheck](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunATCCheck/)| -| [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/), [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/)| +| [Test](stages/Test.md) | - | +| [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/)| | [Confirm](stages/confirm.md) | - | | [Publish](stages/publish.md) | [abapAddonAssemblyKitPublishTargetVector](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitPublishTargetVector/)| diff --git a/documentation/docs/pipelines/abapEnvironment/stages/ATC.md b/documentation/docs/pipelines/abapEnvironment/stages/ATC.md deleted file mode 100644 index 99d712237..000000000 --- a/documentation/docs/pipelines/abapEnvironment/stages/ATC.md +++ /dev/null @@ -1,64 +0,0 @@ -# ATC - -In this stage, ATC checks can be executed using abapEnvironmentRunATCCheck. The step can receive software components or packages. The results are returned in the checkstyle format. With the use of a pipeline extension, quality gates can be configured (see [step documentation](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunATCCheck/) or the "Extensions" section in the [configuration](../configuration.md)). - -## Steps - -The following steps are executed in this stage: - -- [abapEnvironmentRunATCCheck](../../../steps/abapEnvironmentRunATCCheck.md) - -## Stage Parameters - -There are no specifc stage parameters. - -## Stage Activation - -This stage will be active, if the stage configuration in the `config.yml` contains entries for this stage. - -## Configuration Example - -### config.yml - -```yaml -general: - cfApiEndpoint: 'https://api.cf.sap.hana.ondemand.com' - cfOrg: 'myOrg' - cfSpace: 'mySpace' - cfCredentialsId: 'cfAuthentification' - cfServiceInstance: 'abap_system' - cfServiceKeyName: 'JENKINS_SAP_COM_0510' -stages: - ATC: - atcConfig: 'atcConfig.yml' -``` - -### atcConfig.yml - -```yaml -atcobjects: - softwarecomponent: - - name: "/DMO/SWC" -``` - -### ATC.groovy - -```groovy -void call(Map params) { - //access stage name - echo "Start - Extension for stage: ${params.stageName}" - - //access config - echo "Current stage config: ${params.config}" - - //execute original stage as defined in the template - params.originalStage() - - recordIssues tools: [checkStyle(pattern: '**/ATCResults.xml')], qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]] - - echo "End - Extension for stage: ${params.stageName}" -} -return this -``` - -Please note, this file belongs in the extensions folder: `.pipeline/extensions/ATC.groovy` diff --git a/documentation/docs/pipelines/abapEnvironment/stages/Test.md b/documentation/docs/pipelines/abapEnvironment/stages/Test.md new file mode 100644 index 000000000..86dceb729 --- /dev/null +++ b/documentation/docs/pipelines/abapEnvironment/stages/Test.md @@ -0,0 +1,134 @@ +# Test + +This stage contains two sub stages, `ATC` and `AUnit` which can execute ATC checks and AUnit test runs in parallel on an SAP BTP ABAP environment systen. +By default this stage will not run any of the two sub stages `ATC` and `AUnit` if they are not configured. Please keep in mind that the `ATC` and `AUnit` stages need to be configured independently. +The below sections contain more information on the usage and configuration of the `ATC` and `AUnit` stages. + +## ATC + +In this stage, ATC checks can be executed using abapEnvironmentRunATCCheck. The step can receive software components or packages. The results are returned in the checkstyle format. With the use of a pipeline extension, quality gates can be configured (see [step documentation](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunATCCheck/) or the "Extensions" section in the [configuration](../configuration.md)). + +### Steps + +The following steps are executed in this stage: + +- [abapEnvironmentRunATCCheck](../../../steps/abapEnvironmentRunATCCheck.md) + +### Stage Parameters + +There are no specifc stage parameters. + +### Stage Activation + +This stage will be active, if the stage configuration in the `config.yml` contains entries for this stage.. + +### Configuration Example + +#### config.yml + +```yaml +general: + cfApiEndpoint: 'https://api.cf.sap.hana.ondemand.com' + cfOrg: 'myOrg' + cfSpace: 'mySpace' + cfCredentialsId: 'cfAuthentification' + cfServiceInstance: 'abap_system' + cfServiceKeyName: 'JENKINS_SAP_COM_0510' +stages: + ATC: + atcConfig: 'atcConfig.yml' +``` + +#### atcConfig.yml + +```yaml +atcobjects: + softwarecomponent: + - name: "/DMO/SWC" +``` + +#### ATC.groovy + +```groovy +void call(Map params) { + //access stage name + echo "Start - Extension for stage: ${params.stageName}" + + //access config + echo "Current stage config: ${params.config}" + + //execute original stage as defined in the template + params.originalStage() + + recordIssues tools: [checkStyle(pattern: '**/ATCResults.xml')], qualityGates: [[threshold: 1, type: 'TOTAL', unstable: true]] + + echo "End - Extension for stage: ${params.stageName}" +} +return this +``` + +Please note, this file belongs in the extensions folder: `.pipeline/extensions/ATC.groovy` + +## AUnit + +This stage will trigger an AUnit test run an on SAP BTP ABAP Environment system using the abapEnvironmentRunAUnitTest step. + +### Steps + +The following steps are executed in this stage: + +- [abapEnvironmentRunAUnitTest](../../../steps/abapEnvironmentRunAUnitTest.md) + +### Stage Parameters + +There are no specifc stage parameters. + +### Stage Activation + +This stage will be active, if the stage configuration in the `config.yml` contains entries for this stage. + +### Configuration Example + +#### config.yml + +```yaml +general: + cfApiEndpoint: 'https://api.cf.sap.hana.ondemand.com' + cfOrg: 'myOrg' + cfSpace: 'mySpace' + cfCredentialsId: 'cfAuthentification' + cfServiceInstance: 'abap_system' + cfServiceKeyName: 'JENKINS_SAP_COM_0510' +stages: + AUnit: + aunitConfig: 'aunitConfig.yml' +``` + +#### aunitConfig.yml + +Please note that it is recommended to specify each development package you want to be checked as it is not possible to specify structure packages within the `aUnitConfig.yml` file. You can specify complete development packages using the `includesubpackages: false` parameter like in below example configuration. + +```yaml +title: My AUnit run +context: AUnit test run +options: + measurements: none + scope: + ownTests: true + foreignTests: true + riskLevel: + harmless: true + dangerous: true + critical: true + duration: + short: true + medium: true + long: true +objectSet: + - type: unionSet + set: + - type: packageSet + package: + - name: MY_PACKAGE + includeSubpackages: false +``` diff --git a/documentation/docs/scenarios/abapEnvironmentAddons.md b/documentation/docs/scenarios/abapEnvironmentAddons.md index d22d68a71..7da4f236c 100644 --- a/documentation/docs/scenarios/abapEnvironmentAddons.md +++ b/documentation/docs/scenarios/abapEnvironmentAddons.md @@ -225,6 +225,7 @@ If the pipelines receives the error from a backend system during execeution of t | Prepare System | [abapEnvironmentCreateSystem](https://sap.github.io/jenkins-library/steps/abapEnvironmentCreateSystem/), [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/)| BC-CP-ABA | | Clone Repositories | [abapEnvironmentPullGitRepo](https://sap.github.io/jenkins-library/steps/abapEnvironmentPullGitRepo/)| BC-CP-ABA-SC | | ATC | [abapEnvironmentRunATCCheck](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunATCCheck/)| BC-DWB-TOO-ATF | +| AUnit | [abapEnvironmentRunAUnitTest](https://sap.github.io/jenkins-library/steps/abapEnvironmentRunAUnitTest/)| BC-DWB-TOO-ATF | | Build | [cloudFoundryCreateServiceKey](https://sap.github.io/jenkins-library/steps/cloudFoundryCreateServiceKey/)| BC-CP-ABA | | | [abapAddonAssemblyKitReserveNextPackages](https://sap.github.io/jenkins-library/steps/abapAddonAssemblyKitReserveNextPackages/) | BC-UPG-OCS | | | [abapEnvironmentAssemblePackages](https://sap.github.io/jenkins-library/steps/abapEnvironmentAssemblePackages/)| BC-UPG-ADDON | diff --git a/documentation/docs/scenarios/abapEnvironmentTest.md b/documentation/docs/scenarios/abapEnvironmentTest.md index 3b6d9d5b4..c0f865e00 100644 --- a/documentation/docs/scenarios/abapEnvironmentTest.md +++ b/documentation/docs/scenarios/abapEnvironmentTest.md @@ -16,10 +16,18 @@ The pipeline starts with the stage "Prepare System". This stage, however, is opt This stage is responsible for cloning (or pulling) the defined software components (repositories) to the system. +### Run Tests + +This stage will trigger the execution of the `ATC` and `AUnit` stages in parallel. Please find more information on the respective stages below. + ### ATC This stage runs ATC checks on the SAP BTP, ABAP environment system. The results are returned in the "CheckStyle" format. With the help of a stage extension, a plugin can be used to visualize the check results. +### AUnit + +This stage will triger an AUnit run on the SAP BTP, APAB environment system. You can configure the object set that should be checked during the AUnit run. The results of the test run are returned in the "JUnit" format. It is possible to further visualize the AUnit test run results with the help of a stage extension. + ## Prerequisites There are several parts that are required to run the pipeline. diff --git a/documentation/docs/steps/abapEnvironmentRunAUnitTest.md b/documentation/docs/steps/abapEnvironmentRunAUnitTest.md index a879520e5..051baff8d 100644 --- a/documentation/docs/steps/abapEnvironmentRunAUnitTest.md +++ b/documentation/docs/steps/abapEnvironmentRunAUnitTest.md @@ -85,7 +85,7 @@ The following section contains an example of an `aUnitConfig.yml` file. This file must be stored in the same Git folder where the `Jenkinsfile` is stored to run the pipeline. This repository containing the `Jenkinsfile` must be taken as a SCM in the Jenkins pipeline to run the pipeline. You can specify an object set containing the objects that should be checked. These can be for example packages, classes or transport requests containing test classes that can be executed. This must be in the same format as below example for a `aUnitConfig.yml` file. -Note that if you specify a package inside a packageSet to be checked for each package that has to be checked you can configure if you want the subpackages to be included in checks or not. +Note that if you specify a package inside a packageSet to be checked for each package that has to be checked you can configure if you want the subpackages to be included in checks or not. We recommend you to specify each development package you want to be checked as it is not possible to specify structure packages within the `aUnitConfig.yml` file. You can specify complete development packages using the `includesubpackages: false` parameter. See below example for an `aUnitConfig.yml` file containing a package to be checked: @@ -95,8 +95,8 @@ context: My unit tests options: measurements: none scope: - owntests: true - foreigntests: true + ownTests: true + foreignTests: true riskLevel: harmless: true dangerous: true @@ -105,13 +105,13 @@ options: short: true medium: true long: true -objectset: +objectSet: - type: unionSet set: - type: packageSet package: - name: my_package - includesubpackages: false + includeSubpackages: false ``` The following example of an `aUnitConfig.yml` file containing one class and one interface to be checked: @@ -122,8 +122,8 @@ context: My unit tests options: measurements: none scope: - owntests: true - foreigntests: true + ownTests: true + foreignTests: true riskLevel: harmless: true dangerous: true @@ -132,7 +132,7 @@ options: short: true medium: true long: true -objectset: +objectSet: - type: unionSet set: - type: flatObjectSet diff --git a/documentation/mkdocs.yml b/documentation/mkdocs.yml index 9e030d425..92c87272f 100644 --- a/documentation/mkdocs.yml +++ b/documentation/mkdocs.yml @@ -17,7 +17,7 @@ nav: - 'Initial Checks': pipelines/abapEnvironment/stages/initialChecks.md - 'Prepare System': pipelines/abapEnvironment/stages/prepareSystem.md - 'Clone Repositories': pipelines/abapEnvironment/stages/cloneRepositories.md - - 'ATC': pipelines/abapEnvironment/stages/ATC.md + - 'Test': pipelines/abapEnvironment/stages/Test.md - 'Build': pipelines/abapEnvironment/stages/build.md - 'Integration Tests': pipelines/abapEnvironment/stages/integrationTest.md - 'Confirm': pipelines/abapEnvironment/stages/confirm.md @@ -64,6 +64,7 @@ nav: - abapEnvironmentCreateSystem: steps/abapEnvironmentCreateSystem.md - abapEnvironmentPullGitRepo: steps/abapEnvironmentPullGitRepo.md - abapEnvironmentRunATCCheck: steps/abapEnvironmentRunATCCheck.md + - abapEnvironmentRunAUnitTest: steps/abapEnvironmentRunAUnitTest.md - apiProxyDownload: steps/apiProxyDownload.md - artifactPrepareVersion: steps/artifactPrepareVersion.md - batsExecuteTests: steps/batsExecuteTests.md diff --git a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStageDefaults.yml b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStageDefaults.yml index 80f0e88e3..7abc8d7ed 100644 --- a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStageDefaults.yml +++ b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStageDefaults.yml @@ -12,20 +12,29 @@ stages: abapSystemIsDevelopmentAllowed: 'false' abapSystemSizeOfPersistence: 4 abapSystemSizeOfRuntime: 1 + cfServiceKeyName: 'sap_com_0510' + cfServiceKeyConfig: '{"scenario_id":"SAP_COM_0510","type":"basic"}' 'Clone Repositories': + cfServiceKeyName: 'sap_com_0510' ordinal: 30 - ATC: + 'ATC': ordinal: 40 + cfServiceKeyName: 'sap_com_0510' + + 'AUnit': + ordinal: 50 + cfServiceKeyName: 'sap_com_0735' + cfServiceKeyConfig: '{"scenario_id":"SAP_COM_0735","type":"basic"}' Build: - ordinal: 50 + ordinal: 60 cfServiceKeyName: 'sap_com_0582' cfServiceKeyConfig: '{"scenario_id":"SAP_COM_0582","type":"basic"}' 'Integration Tests': - ordinal: 60 + ordinal: 70 cfService: 'abap' cfServicePlan: 'saas_oem' abapSystemIsDevelopmentAllowed: 'false' @@ -35,12 +44,12 @@ stages: includeAddon: 'true' Confirm: - ordinal: 70 + ordinal: 80 Publish: - ordinal: 80 + ordinal: 90 targetVectorScope: 'P' Post: - ordinal: 90 + ordinal: 100 cfDeleteServiceKeys: true diff --git a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStages.yml b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStages.yml index cac0ce322..ba51809c5 100644 --- a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStages.yml +++ b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStages.yml @@ -2,8 +2,9 @@ stages: Init: {} Initial Checks: {} Prepare System: {} - Clone Repositories: {} + AUnit: {} ATC: {} + Clone Repositories: {} Build: {} Integration Tests: {} Confirm: {} diff --git a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStashSettings.yml b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStashSettings.yml index 904cb1d05..1577974a5 100644 --- a/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStashSettings.yml +++ b/resources/com.sap.piper/pipeline/abapEnvironmentPipelineStashSettings.yml @@ -19,7 +19,12 @@ Init: - source stashes: [] -ATC: +'ATC': + unstash: + - source + stashes: [] + +'AUnit': unstash: - source stashes: [] diff --git a/resources/metadata/abapEnvironmentRunAUnitTest.yaml b/resources/metadata/abapEnvironmentRunAUnitTest.yaml index c1c93b508..4ffdb5ba3 100644 --- a/resources/metadata/abapEnvironmentRunAUnitTest.yaml +++ b/resources/metadata/abapEnvironmentRunAUnitTest.yaml @@ -103,7 +103,7 @@ spec: scope: - PARAMETERS - STAGES - - STEPS2 + - STEPS mandatory: true secret: true resourceRef: diff --git a/test/groovy/templates/AbapEnvironmentPipelineStageATCTest.groovy b/test/groovy/templates/AbapEnvironmentPipelineStageATCTest.groovy new file mode 100644 index 000000000..2fb7cedc2 --- /dev/null +++ b/test/groovy/templates/AbapEnvironmentPipelineStageATCTest.groovy @@ -0,0 +1,46 @@ +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 AbapEnvironmentPipelineStageATCTest 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 = 'ATC' + + helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body -> + assertThat(m.stageName, is('ATC')) + return body() + }) + helper.registerAllowedMethod('abapEnvironmentRunATCCheck', [Map.class], {m -> stepsCalled.add('abapEnvironmentRunATCCheck')}) + } + + @Test + void testAbapEnvironmentRunTests() { + + nullScript.commonPipelineEnvironment.configuration.runStage = [] + jsr.step.abapEnvironmentPipelineStageATC(script: nullScript) + + assertThat(stepsCalled, hasItems('abapEnvironmentRunATCCheck')) + } +} diff --git a/test/groovy/templates/AbapEnvironmentPipelineStageAUnitTest.groovy b/test/groovy/templates/AbapEnvironmentPipelineStageAUnitTest.groovy new file mode 100644 index 000000000..6b3377dc2 --- /dev/null +++ b/test/groovy/templates/AbapEnvironmentPipelineStageAUnitTest.groovy @@ -0,0 +1,60 @@ +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 AbapEnvironmentPipelineStageAUnitTest 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 = 'AUnit' + + helper.registerAllowedMethod('piperStageWrapper', [Map.class, Closure.class], {m, body -> + assertThat(m.stageName, is('AUnit')) + return body() + }) + helper.registerAllowedMethod('abapEnvironmentRunAUnitTest', [Map.class], {m -> stepsCalled.add('abapEnvironmentRunAUnitTest')}) + helper.registerAllowedMethod('cloudFoundryCreateServiceKey', [Map.class], {m -> stepsCalled.add('cloudFoundryCreateServiceKey')}) + } + + @Test + void testAbapEnvironmentRunTestsWithoutHost() { + nullScript.commonPipelineEnvironment.configuration.runStage = [ + 'AUnit': true + ] + jsr.step.abapEnvironmentPipelineStageAUnit(script: nullScript) + + assertThat(stepsCalled, hasItems('abapEnvironmentRunAUnitTest','cloudFoundryCreateServiceKey')) + } + + @Test + void testAbapEnvironmentRunTestsWithHost() { + nullScript.commonPipelineEnvironment.configuration.runStage = [ + 'AUnit': true + ] + jsr.step.abapEnvironmentPipelineStageAUnit(script: nullScript, host: 'abc.com') + + assertThat(stepsCalled, hasItems('abapEnvironmentRunAUnitTest')) + assertThat(stepsCalled, not(hasItems('cloudFoundryCreateServiceKey'))) + } + +} diff --git a/test/groovy/templates/AbapEnvironmentPipelineStageCloneRepositoriesTest.groovy b/test/groovy/templates/AbapEnvironmentPipelineStageCloneRepositoriesTest.groovy index 9badb0990..76fb6632b 100644 --- a/test/groovy/templates/AbapEnvironmentPipelineStageCloneRepositoriesTest.groovy +++ b/test/groovy/templates/AbapEnvironmentPipelineStageCloneRepositoriesTest.groovy @@ -43,9 +43,7 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { @Test void testAbapEnvironmentPipelineStageCloneRepositoriesPull() { - nullScript.commonPipelineEnvironment.configuration.runStage = [ - 'Prepare System': true - ] + nullScript.commonPipelineEnvironment.configuration.runStage = [] jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'Pull') assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo')) @@ -56,10 +54,7 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { @Test void testAbapEnvironmentPipelineStageCloneRepositoriesClone() { - nullScript.commonPipelineEnvironment.configuration.runStage = [ - 'Prepare System': true - ] - + nullScript.commonPipelineEnvironment.configuration.runStage = [] jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'Clone') assertThat(stepsCalled, hasItems('abapEnvironmentCloneGitRepo')) @@ -69,10 +64,7 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { @Test void testAbapEnvironmentPipelineStageCloneRepositoriesCheckoutPull() { - nullScript.commonPipelineEnvironment.configuration.runStage = [ - 'Prepare System': true - ] - + nullScript.commonPipelineEnvironment.configuration.runStage = [] jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'CheckoutPull') assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch')) @@ -82,10 +74,7 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { @Test void testAbapEnvironmentPipelineStageCloneRepositoriesPullCheckoutPull() { - nullScript.commonPipelineEnvironment.configuration.runStage = [ - 'Prepare System': true - ] - + nullScript.commonPipelineEnvironment.configuration.runStage = [] jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript, strategy: 'AddonBuild') assertThat(stepsCalled, not(hasItems('abapEnvironmentPullGitRepo', 'abapEnvironmentCheckoutBranch'))) @@ -95,10 +84,7 @@ class AbapEnvironmentPipelineStageCloneRepositoriesTest extends BasePiperTest { @Test void testAbapEnvironmentPipelineStageCloneRepositoriesNoStrategy() { - nullScript.commonPipelineEnvironment.configuration.runStage = [ - 'Prepare System': true - ] - + nullScript.commonPipelineEnvironment.configuration.runStage = [] jsr.step.abapEnvironmentPipelineStageCloneRepositories(script: nullScript) assertThat(stepsCalled, hasItems('abapEnvironmentPullGitRepo')) diff --git a/test/groovy/templates/AbapEnvironmentPipelineTest.groovy b/test/groovy/templates/AbapEnvironmentPipelineTest.groovy index 31c7fd4bb..a6372b8f4 100644 --- a/test/groovy/templates/AbapEnvironmentPipelineTest.groovy +++ b/test/groovy/templates/AbapEnvironmentPipelineTest.groovy @@ -129,6 +129,7 @@ class AbapEnvironmentPipelineTest extends BasePiperTest { }) helper.registerAllowedMethod('steps', [Closure], null) + helper.registerAllowedMethod('parallel', [Closure], null) helper.registerAllowedMethod('post', [Closure], {c -> c()}) helper.registerAllowedMethod('success', [Closure], {c -> c()}) helper.registerAllowedMethod('failure', [Closure], {c -> c()}) @@ -136,7 +137,6 @@ class AbapEnvironmentPipelineTest extends BasePiperTest { helper.registerAllowedMethod('unstable', [Closure], {c -> c()}) helper.registerAllowedMethod('unsuccessful', [Closure], {c -> c()}) helper.registerAllowedMethod('cleanup', [Closure], {c -> c()}) - helper.registerAllowedMethod('input', [Map], {m -> return null}) helper.registerAllowedMethod('abapEnvironmentPipelineStageInit', [Map.class], {m -> @@ -151,6 +151,10 @@ class AbapEnvironmentPipelineTest extends BasePiperTest { stepsCalled.add('abapEnvironmentPipelineStageCloneRepositories') }) + helper.registerAllowedMethod('abapEnvironmentPipelineStageAUnit', [Map.class], {m -> + stepsCalled.add('abapEnvironmentPipelineStageAUnit') + }) + helper.registerAllowedMethod('abapEnvironmentPipelineStageATC', [Map.class], {m -> stepsCalled.add('abapEnvironmentPipelineStageATC') }) @@ -186,23 +190,28 @@ class AbapEnvironmentPipelineTest extends BasePiperTest { @Test void testAbapEnvironmentPipelineNoPrepareNoCleanup() { + nullScript.commonPipelineEnvironment.configuration.runStage = [ 'Clone Repositories': true, + 'Tests': true, 'ATC': true, + 'AUnit': true, ] + jsr.step.abapEnvironmentPipeline(script: nullScript) assertThat(stepsCalled, hasItems( 'abapEnvironmentPipelineStageInit', 'abapEnvironmentPipelineStageCloneRepositories', 'abapEnvironmentPipelineStageATC', + 'abapEnvironmentPipelineStageAUnit', 'abapEnvironmentPipelineStagePost' )) assertThat(stepsCalled, not(hasItem('abapEnvironmentPipelineStagePrepareSystem'))) } @Test - void testAbapEnvironmentPipelineNoCloneNoATC() { + void testAbapEnvironmentPipelineNoCloneNoRunTests() { nullScript.commonPipelineEnvironment.configuration.runStage = [ 'Prepare System': true, @@ -216,6 +225,7 @@ class AbapEnvironmentPipelineTest extends BasePiperTest { )) assertThat(stepsCalled, not(hasItem('abapEnvironmentPipelineStageCloneRepositories'))) assertThat(stepsCalled, not(hasItem('abapEnvironmentPipelineStageATC'))) + assertThat(stepsCalled, not(hasItem('abapEnvironmentPipelineStageAUnit'))) } @Test @@ -224,7 +234,9 @@ class AbapEnvironmentPipelineTest extends BasePiperTest { nullScript.commonPipelineEnvironment.configuration.runStage = [ 'Prepare System': true, 'Clone Repositories': true, + 'Tests': true, 'ATC': true, + 'AUnit': true, 'Build': true, 'Integration Tests': true, 'Publish': true @@ -236,6 +248,7 @@ class AbapEnvironmentPipelineTest extends BasePiperTest { 'abapEnvironmentPipelineStagePrepareSystem', 'abapEnvironmentPipelineStageCloneRepositories', 'abapEnvironmentPipelineStageATC', + 'abapEnvironmentPipelineStageAUnit', 'abapEnvironmentPipelineStagePost', 'abapEnvironmentPipelineStageBuild', 'abapEnvironmentPipelineStageInitialChecks', @@ -244,4 +257,39 @@ class AbapEnvironmentPipelineTest extends BasePiperTest { 'abapEnvironmentPipelineStageIntegrationTests' )) } + + @Test + void testAbapEnvironmentPipelineATCOnly() { + + nullScript.commonPipelineEnvironment.configuration.runStage = [ + 'ATC': true, + ] + jsr.step.abapEnvironmentPipeline(script: nullScript) + + assertThat(stepsCalled, hasItems( + 'abapEnvironmentPipelineStageInit', + 'abapEnvironmentPipelineStageATC', + 'abapEnvironmentPipelineStagePost' + )) + assertThat(stepsCalled, not(hasItems( + 'abapEnvironmentPipelineStageAUnit' + ))) + } + @Test + void testAbapEnvironmentPipelineAunitOnly() { + + nullScript.commonPipelineEnvironment.configuration.runStage = [ + 'AUnit': true, + ] + jsr.step.abapEnvironmentPipeline(script: nullScript) + + assertThat(stepsCalled, hasItems( + 'abapEnvironmentPipelineStageInit', + 'abapEnvironmentPipelineStageAUnit', + 'abapEnvironmentPipelineStagePost' + )) + assertThat(stepsCalled, not(hasItems( + 'abapEnvironmentPipelineStageATC' + ))) + } } diff --git a/vars/abapEnvironmentPipeline.groovy b/vars/abapEnvironmentPipeline.groovy index d08fc9327..2135cec00 100644 --- a/vars/abapEnvironmentPipeline.groovy +++ b/vars/abapEnvironmentPipeline.groovy @@ -33,11 +33,21 @@ void call(parameters) { } } - stage('ATC') { - when {expression {return parameters.script.commonPipelineEnvironment.configuration.runStage?.get(env.STAGE_NAME)}} - steps { - abapEnvironmentPipelineStageATC script: parameters.script - } + stage('Test') { + parallel { + stage('ATC') { + when {expression {return parameters.script.commonPipelineEnvironment.configuration.runStage?.get(env.STAGE_NAME)}} + steps { + abapEnvironmentPipelineStageATC script: parameters.script + } + } + stage('AUnit') { + when {expression {return parameters.script.commonPipelineEnvironment.configuration.runStage?.get(env.STAGE_NAME)}} + steps { + abapEnvironmentPipelineStageAUnit script: parameters.script + } + } + } } stage('Build') { diff --git a/vars/abapEnvironmentPipelineStageAUnit.groovy b/vars/abapEnvironmentPipelineStageAUnit.groovy new file mode 100644 index 000000000..df22f2d2e --- /dev/null +++ b/vars/abapEnvironmentPipelineStageAUnit.groovy @@ -0,0 +1,41 @@ +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 + +@Field String STEP_NAME = getClass().getName() +@Field Set GENERAL_CONFIG_KEYS = [] +@Field STAGE_STEP_KEYS = [ + /** Starts an AUnit test run on the ABAP Environment instance */ + 'abapEnvironmentRunAUnitTest', + /** Creates Communication Arrangements for ABAP Environment instance via the cloud foundry command line interface */ + 'cloudFoundryCreateServiceKey', + /** Parameter for host config */ + 'host' +] +@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus(STAGE_STEP_KEYS) +@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS + +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 + } + abapEnvironmentRunAUnitTest script: parameters.script + } +}