metadata:
  name: gctsExecuteABAPQualityChecks
  description: Runs ABAP unit tests and ATC (ABAP Test Cockpit) checks for a specified object scope.
  longDescription: |
    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.
    <br/>
    The results of the checks are stored in a [Checkstyle](https://checkstyle.sourceforge.io/) format. With the help of the Jenkins [Warnings-Next-Generation](https://plugins.jenkins.io/warnings-ng/) 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 the Jenkins plug-in, you need to use the `recordIssues` step, as displayed in the `Example` section below.
    <br/>
    You can use this step as of SAP S/4HANA 2020 with SAP Note [3159798](https://launchpad.support.sap.com/#/notes/3159798) implemented.

spec:
  inputs:
    secrets:
      - name: abapCredentialsId
        description: 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.
        type: jenkins
    params:
      - name: username
        type: string
        description: 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.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
        secret: true
        resourceRef:
          - name: abapCredentialsId
            type: secret
            param: username
      - name: password
        type: string
        description: 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.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
        secret: true
        resourceRef:
          - name: abapCredentialsId
            type: secret
            param: password
      - name: host
        type: string
        description: Protocol and host of the ABAP system, including the port. Please provide it in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
      - name: repository
        type: string
        description: Name (ID) of the local repository on the ABAP system
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
      - name: client
        type: string
        description: Client of the ABAP system in which you want to execute the checks
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
      - name: aUnitTest
        type: bool
        default: true
        description: |
          Indication whether you want to execute the ABAP Unit tests. If the ABAP Unit tests fail, the results are mapped as follows to the statuses available in the Jenkins plugin. (Successful ABAP unit test results are not displayed.)
          <br/>
          - Failed with severity `fatal` is displayed as an `Error`.
          <br/>
          - Failed with severity `critical` is displayed as an `Error`.
          <br/>
          - Failed with severity `warning` is displayed as a `Warning`.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: atcCheck
        type: bool
        default: true
        description: |
          Indication whether you want to execute the ATC checks. If the ATC checks result in errors with priorities 1 and 2, they are considered as failed. The results are mapped as follows to the statuses available in the Jenkins plugin. (Successful ATC check results are not displayed.)
          <br/>
          - Priorities 1 and 2 are displayed as an `Error`.
          <br/>
          - Priority 3 is displayed as a `Warning`.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: atcVariant
        type: string
        default: "DEFAULT"
        description: Variant for ATC checks
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: scope
        type: string
        default: repository
        enum:
          - localChangedObjects
          - remoteChangedObjects
          - localChangedPackages
          - remoteChangedPackages
          - repository
          - packages
        description: |
          Scope of objects for which you want to execute the checks:
          <br/>
          - `localChangedObjects`: The object scope is derived from the last activity in the local repository. The checks are executed for the individual objects.
          <br/>
          - `remoteChangedObjects`: The object scope is the delta between the commit that triggered the pipeline and the current commit in the remote repository. The checks are executed for the individual objects.
          <br/>
          - `localChangedPackages`: The object scope is derived from the last activity in the local repository. All objects are resolved into packages. The checks are executed for the packages.
          <br/>
          - `remoteChangedPackages`: The object scope is the 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.
          <br/>
          - `repository`: The object scope comprises 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.
          <br/>
          - `packages`: The object scope comprises all packages that are part of the local repository. The checks are executed for the packages.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: commit
        type: string
        description: ID of the commit that triggered the pipeline or any other commit used to calculate the object scope. Specifying a commit is mandatory for the `remoteChangedObjects` and `remoteChangedPackages` scopes.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: false
      - name: workspace
        type: string
        description: Absolute path to the directory that contains the source code that your CI/CD tool checks out. For example, in Jenkins, the workspace parameter is `/var/jenkins_home/workspace/<jobName>/`. As an alternative, you can use Jenkins's predefined environmental variable `WORKSPACE`.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
      - name: atcResultsFileName
        type: string
        description: Specifies an output file name for the results of the ATC checks.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: false
        default: "ATCResults.xml"
      - name: aUnitResultsFileName
        type: string
        description: Specifies an output file name for the results of the ABAP Unit tests.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: false
        default: "AUnitResults.xml"
