Skip to content

gctsExecuteABAPUnitTests

Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope.

Description

This step executes ABAP unit test and ATC checks for a specified scope of objects that exist in a local Git repository on an ABAP system. Depending on your use case, you can specify a scope of objects for which you want to execute the checks. In addition, you can choose whether you want to execute only ABAP units tests, or only ATC checks, or both. By default, both checks are executed. The results of the checks are stored in a Checkstyle format. With the help of the Jenkins Warnings-Next-Generation Plugin), you can view the issues found, and navigate to the exact line of the source code where the issue occurred. To make the findings visible in Jenkins interface, you will need to use step recordIssues. An example will be shown in the Example section.
You can use this step as of SAP S/4HANA 2020.

Usage

We recommend to define values of step parameters via .pipeline/config.yml file.
In this case, calling the step is essentially reduced to defining the step name.
Calling the step can be done either in an orchestrator specific way (e.g. via a Jenkins library step) or on the command line.

library('piper-lib-os')

gctsExecuteABAPUnitTests script: this
piper gctsExecuteABAPUnitTests

Prerequisites

  • ATC checks are enabled in transaction ATC in the ABAP systems where you want to use the step.
  • gCTS is available and configured in the ABAP systems where you want to use the step.
  • The Warnings-Next-Generation Plugin is installed in Jenkins.

Parameters

Overview - Step

Name Mandatory Additional information
client yes
host yes
password (yes) Secret pass via ENV or Jenkins credentials (abapCredentialsId)
repository yes
script (yes) Jenkins only reference to Jenkins main pipeline script
username (yes) Secret pass via ENV or Jenkins credentials (abapCredentialsId)
workspace yes
aUnitResultsFileName no
aUnitTest no
atcCheck no
atcResultsFileName no
atcVariant no
commit no
scope no
verbose no activates debug output

Overview - Execution Environment

Orchestrator-specific only

These parameters are relevant for orchestrator usage and not considered when using the command line option.

Name Mandatory Additional information

Details

aUnitResultsFileName

Specifies output file name for the results from the AUnit tests

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default AUnitResults.xml
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

aUnitTest

Indication whether you want to execute the unit test checks.

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default true
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

atcCheck

Indication whether you want to execute the ATC checks.

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default true
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

atcResultsFileName

Specifies output file name for the results from the ATC checks

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default ATCResults.xml
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

atcVariant

Variant for ATC checks

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default DEFAULT_REMOTE_REF
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

client

Client of the ABAP system in which you want to execute the checks

back to overview

Scope Details
Aliases -
Type string
Mandatory yes
Default $PIPER_client (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

commit

ID of the commit that triggered the pipeline or any other commit to compare objects. For scopes localChangedObjects, remoteChangedObjects, localChangedPackages and remoteChangedPackages secifying a commit it's mandatory.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default $PIPER_commit (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

host

Protocol and host of the ABAP system, including the port. Please provide in the format ://:. Supported protocols are http and https.

back to overview

Scope Details
Aliases -
Type string
Mandatory yes
Default $PIPER_host (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

password

Password of the ABAP user that authenticates to the ABAP system. Note – Don´t provide this parameter directly. Either set it in the environment, or in the Jenkins credentials store, and provide the ID as value of the abapCredentialsId parameter.

back to overview

Scope Details
Aliases -
Type string
Mandatory yes
Default $PIPER_password (if set)
Secret yes
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references Jenkins credential id:
  id: abapCredentialsId
  reference to: password

repository

Name (ID) of the local repository on the ABAP system

back to overview

Scope Details
Aliases -
Type string
Mandatory yes
Default $PIPER_repository (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

scope

Scope of objects for which you want to execute the checks:

  • localChangedObjects - object delta between the commit that triggered the pipeline and the current commit in the local repository. The checks are executed for the individual objects.
  • remoteChangedObjects - object delta between the commit that triggered the pipeline and the current commit in the remote repository. The checks are executed for the individual objects.
  • localChangedPackages - object delta between the commit that triggered the pipeline and the current commit in the local repository. All objects are resolved into packages. The checks are executed for the packages.
  • remoteChangedPackages - object delta between the commit that triggered the pipeline and the current commit in the remote repository. All objects are resolved into packages. The checks are executed for the packages.
  • repository - all objects that are part of the local repository. The checks are executed for the individual objects. Packages (DEVC) are excluded. This is the default scope.
  • packages - all packages that are part of the local repository . The checks are executed for the packages.

back to overview

Scope Details
Aliases -
Type string
Mandatory no
Default repository
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

script

Jenkins-specific: Used for proper environment setup.

The common script environment of the Jenkinsfile running. Typically the reference to the script calling the pipeline step is provided with the this parameter, as in script: this. This allows the function to access the commonPipelineEnvironment for retrieving, e.g. configuration parameters.

back to overview

Scope Details
Aliases -
Type Jenkins Script
Mandatory yes
Default
Secret no
Configuration scope
  • ☐ parameter
  • ☐ general
  • ☐ steps
  • ☐ stages
Resource references none

username

User that authenticates to the ABAP system. Note – Don´t provide this parameter directly. Either set it in the environment, or in the Jenkins credentials store, and provide the ID as value of the abapCredentialsId parameter.

back to overview

Scope Details
Aliases -
Type string
Mandatory yes
Default $PIPER_username (if set)
Secret yes
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references Jenkins credential id:
  id: abapCredentialsId
  reference to: username

verbose

verbose output

back to overview

Scope Details
Aliases -
Type bool
Mandatory no
Default false
Possible values - true
- false
Secret no
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages
Resource references none

workspace

Absolute path to directory which contains the source code that your CI/CD tool checks out. For example in Jenkins, the workspace parameter is /var/jenkins_home/workspace//

back to overview

Scope Details
Aliases -
Type string
Mandatory yes
Default $PIPER_workspace (if set)
Secret no
Configuration scope
  • ☒ parameter
  • ☐ general
  • ☒ steps
  • ☒ stages
Resource references none

abapCredentialsId

Jenkins-specific: Used for proper environment setup. See using credentials for details.

ID taken from the Jenkins credentials store containing user name and password of the user that authenticates to the ABAP system on which you want to execute the checks.

back to overview

Scope Details
Aliases -
Type string
Configuration scope
  • ☒ parameter
  • ☒ general
  • ☒ steps
  • ☒ stages

Example

Example configuration for the use in a Jenkinsfile.

gctsExecuteABAPUnitTests(
  script: this,
  host: 'https://abap.server.com:port',
  client: '000',
  abapCredentialsId: 'ABAPUserPasswordCredentialsId',
  repository: 'myrepo',
  scope: 'localChangedObjects',
  commit: "${GIT_COMMIT}",
  workspace: "${WORKSPACE}"

  )

Example configuration for the use in a yaml config file (such as .pipeline/config.yaml).

steps:
  <...>
  gctsExecuteABAPUnitTests:
    host: 'https://abap.server.com:port'
    client: '000'
    abapCredentialsId: 'ABAPUserPasswordCredentialsId'
    repository: 'myrepo'
    scope: 'remoteChangedObjects'
    commit: '38abb4814ae46b98e8e6c3e718cf1782afa9ca90'
    workspace: '/var/jenkins_home/workspace/myFirstPipeline'

Example configuration when you define scope: repository or packages. For these two cases you do not need to specify a commit.

steps:
  <...>
  gctsExecuteABAPUnitTests:
    host: 'https://abap.server.com:port'
    client: '000'
    abapCredentialsId: 'ABAPUserPasswordCredentialsId'
    repository: 'myrepo'
    scope: 'repository'
    workspace: '/var/jenkins_home/workspace/myFirstPipeline'

Example configuration when you want to execute only ABAP Unit Test.

steps:
  <...>
  gctsExecuteABAPUnitTests:
    host: 'https://abap.server.com:port'
    client: '000'
    abapCredentialsId: 'ABAPUserPasswordCredentialsId'
    repository: 'myrepo'
    atcCheck: false
    scope: 'packages'
    workspace: '/var/jenkins_home/workspace/myFirstPipeline'

Example configuration for the use of recordIssue step to make the findings visible in Jenkins interface.

stage('ABAP Unit Tests') {
  steps{

   script{

     try{
           gctsExecuteABAPUnitTests(
              script: this,
              commit: "${GIT_COMMIT}",
              workspace: "${WORKSPACE}")
        }
          catch (Exception ex) {
            currentBuild.result = 'FAILURE'
            unstable(message: "${STAGE_NAME} is unstable")
             }

        }
      }
    }
stage('Results in Checkstyle') {
  steps{

     recordIssues(
          enabledForFailure: true, aggregatingResults: true,
          tools: [checkStyle(pattern: 'ATCResults.xml', reportEncoding: 'UTF8'),checkStyle(pattern: 'AUnitResults.xml', reportEncoding: 'UTF8')]
       )

      }
    }

}

Note: If you have disabled atcCheck or aUnitTest, than you also need to remove the corresponding ATCResults.xml or AUnitResults.xml from recordIssues step. In the example below the atcCheck was disabled, so ATCResults.xml was removed.

recordIssues(
  enabledForFailure: true, aggregatingResults: true,
  tools: [checkStyle(pattern: 'AUnitResults.xml', reportEncoding: 'UTF8')]

)