metadata:
  name: abapEnvironmentBuild
  description: "Executes builds as defined with the build framework"
  longDescription: |
    Executes builds as defined with the build framework. Transaction overview /n/BUILD/OVERVIEW
spec:
  inputs:
    secrets:
      - name: abapCredentialsId
        description: Jenkins credentials ID containing user and password to authenticate to the Cloud Platform ABAP Environment system or the Cloud Foundry API
        type: jenkins
        aliases:
          - name: cfCredentialsId
          - name: credentialsId
    params:
      - name: cfApiEndpoint
        type: string
        description: Cloud Foundry API endpoint
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/apiEndpoint
      - name: cfOrg
        type: string
        description: Cloud Foundry target organization
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/org
      - name: cfSpace
        type: string
        description: Cloud Foundry target space
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/space
      - name: cfServiceInstance
        type: string
        description: Cloud Foundry Service Instance
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/serviceInstance
      - name: cfServiceKeyName
        type: string
        description: Cloud Foundry Service Key
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/serviceKey
          - name: cloudFoundry/serviceKeyName
          - name: cfServiceKey
      - name: host
        description: Specifies the host address of the SAP Cloud Platform ABAP Environment system
        type: string
        mandatory: false
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
      - name: abapSourceClient
        description: Specifies the client of the SAP Cloud Platform ABAP Environment system, use only in combination with host
        type: string
        mandatory: false
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
      - name: username
        type: string
        description: User
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
        secret: true
      - name: password
        type: string
        description: Password
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
        secret: true
      - name: phase
        type: string
        mandatory: true
        description: Phase as specified in the build script in the backend system
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: values
        type: string
        description: Input values for the build framework, please enter in the format '[{"value_id":"Id1","value":"value1"},{"value_id":"Id2","value":"value2"}]'
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: false
      - name: downloadAllResultFiles
        type: bool
        mandatory: true
        default: false
        description: If true, all build artefacts are downloaded
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: downloadResultFilenames
        type: "[]string"
        mandatory: false
        description: Only the specified files are downloaded. If downloadAllResultFiles is true, this parameter is ignored
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: publishAllDownloadedResultFiles
        type: bool
        mandatory: true
        default: false
        description: If true, it publishes all downloaded files
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: publishResultFilenames
        type: "[]string"
        mandatory: false
        description: Only the specified files get published, in case the file was not downloaded before an error occures
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: subDirectoryForDownload
        type: string
        mandatory: false
        description: Target directory to store the downloaded files, {buildID} and {taskID} can be used and will be resolved accordingly
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
      - name: filenamePrefixForDownload
        type: string
        mandatory: false
        description: Filename prefix for the downloaded files, {buildID} and {taskID} can be used and will be resolved accordingly
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
      - name: treatWarningsAsError
        type: bool
        mandatory: true
        default: false
        description: If a warrning occures, the step will be set to unstable
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: maxRuntimeInMinutes
        type: int
        description: maximal runtime of the step in minutes
        mandatory: true
        default: 360
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: pollingIntervalInSeconds
        type: int
        description: wait time in seconds till next status request in the backend system
        mandatory: true
        default: 60
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: certificateNames
        type: "[]string"
        description: certificates for the backend system, this certificates needs to be stored in .pipeline/trustStore
        mandatory: false
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
      - name: cpeValues
        type: string
        description: Values taken from the previous step, if a value was also specified in the config file, the value from cpe will be discarded
        mandatory: false
        resourceRef:
          - name: commonPipelineEnvironment
            param: abap/buildValues
      - name: useFieldsOfAddonDescriptor
        type: string
        description: use fields of the addonDescriptor in the cpe as input values. Please enter in the format '[{"use":"Name","renameTo":"SWC"}]'
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: false
      - name: conditionOnAddonDescriptor
        type: string
        description: normally if useFieldsOfAddonDescriptor is not initial, a build is triggered for each repository in the addonDescriptor. This can be changed by posing conditions.
                     Please enter in the format '[{"field":"Status","operator":"==","value":"P"}]'
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: false
      - name: stopOnFirstError
        type: bool
        default: false
        description: If false, it does not stop if an error occured for one repository in the addonDescriptor, but continues with the next repository. However the step is marked as failed in the end if an error occured.
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
      - name: addonDescriptor
        type: string
        description: Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions
        mandatory: false
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        resourceRef:
          - name: commonPipelineEnvironment
            param: abap/addonDescriptor
  outputs:
    resources:
      - name: commonPipelineEnvironment
        type: piperEnvironment
        params:
          - name: abap/buildValues
  containers:
    - name: cf
      image: ppiper/cf-cli:7
