1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-07-17 01:42:43 +02:00

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 <daniel.mieg@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
This commit is contained in:
Dominik Lendle
2021-11-11 15:10:14 +01:00
committed by GitHub
parent df441683f7
commit f67cbbe0a7
22 changed files with 436 additions and 139 deletions

View File

@ -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/)|

View File

@ -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.

View File

@ -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/)|

View File

@ -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`

View File

@ -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
```