2018-08-15 11:53:28 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2018-03-13 10:31:01 +02:00
|
|
|
import com.sap.piper.MtaUtils
|
2018-08-15 11:53:28 +02:00
|
|
|
import com.sap.piper.Utils
|
2018-03-19 19:29:41 +02:00
|
|
|
import com.sap.piper.tools.JavaArchiveDescriptor
|
|
|
|
import com.sap.piper.tools.ToolDescriptor
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
import groovy.transform.Field
|
2017-11-24 16:59:34 +02:00
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
@Field def STEP_NAME = 'mtaBuild'
|
2018-02-08 14:18:04 +02:00
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
@Field Set GENERAL_CONFIG_KEYS = []
|
|
|
|
@Field Set STEP_CONFIG_KEYS = [
|
|
|
|
'applicationName',
|
|
|
|
'buildTarget',
|
2018-09-04 11:32:54 +02:00
|
|
|
'dockerImage',
|
2018-08-15 11:53:28 +02:00
|
|
|
'extension',
|
|
|
|
'mtaJarLocation'
|
|
|
|
]
|
2018-09-04 11:32:54 +02:00
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([
|
|
|
|
'dockerOptions'
|
|
|
|
])
|
2018-02-08 14:18:04 +02:00
|
|
|
|
2018-09-12 10:32:30 +02:00
|
|
|
void call(Map parameters = [:]) {
|
2018-09-04 11:32:54 +02:00
|
|
|
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
2018-02-08 14:18:04 +02:00
|
|
|
final script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
// load default & individual configuration
|
2018-10-17 11:05:20 +02:00
|
|
|
Map configuration = ConfigurationHelper.newInstance(this)
|
2018-09-07 10:08:16 +02:00
|
|
|
.loadStepDefaults()
|
2018-08-15 11:53:28 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
2018-09-04 11:32:54 +02:00
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName ?: env.STAGE_NAME, STEP_CONFIG_KEYS)
|
2018-08-15 11:53:28 +02:00
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.use()
|
2018-02-08 14:18:04 +02:00
|
|
|
|
2018-08-15 11:53:28 +02:00
|
|
|
new Utils().pushToSWA([step: STEP_NAME], configuration)
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
dockerExecute(script: script, dockerImage: configuration.dockerImage, dockerOptions: configuration.dockerOptions) {
|
|
|
|
def java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1')
|
|
|
|
java.verify(this, configuration)
|
2018-02-21 13:48:14 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
def mta = new JavaArchiveDescriptor('SAP Multitarget Application Archive Builder', 'MTA_JAR_LOCATION', 'mtaJarLocation', '1.0.6', '-v', java)
|
|
|
|
mta.verify(this, configuration)
|
2018-02-20 14:09:16 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
def mtaYamlName = "mta.yaml"
|
|
|
|
def applicationName = configuration.applicationName
|
2018-03-13 10:31:01 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
if (!fileExists(mtaYamlName)) {
|
|
|
|
if (!applicationName) {
|
|
|
|
echo "'applicationName' not provided as parameter - will not try to generate ${mtaYamlName} file"
|
|
|
|
} else {
|
|
|
|
MtaUtils mtaUtils = new MtaUtils(this)
|
|
|
|
mtaUtils.generateMtaDescriptorFromPackageJson("package.json", mtaYamlName, applicationName)
|
|
|
|
}
|
2018-03-21 13:29:15 +02:00
|
|
|
}
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
def mtaYaml = readYaml file: mtaYamlName
|
2018-03-19 19:29:41 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
//[Q]: Why not yaml.dump()? [A]: This reformats the whole file.
|
|
|
|
sh "sed -ie \"s/\\\${timestamp}/`date +%Y%m%d%H%M%S`/g\" \"${mtaYamlName}\""
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
def id = mtaYaml.ID
|
|
|
|
if (!id) {
|
|
|
|
error "Property 'ID' not found in ${mtaYamlName} file."
|
|
|
|
}
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
def mtarFileName = "${id}.mtar"
|
|
|
|
def mtaJar = mta.getCall(this, configuration)
|
|
|
|
def buildTarget = configuration.buildTarget
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
def mtaCall = "${mtaJar} --mtar ${mtarFileName} --build-target=${buildTarget}"
|
2018-04-17 17:35:10 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
if (configuration.extension) mtaCall += " --extension=$configuration.extension"
|
|
|
|
mtaCall += ' build'
|
2018-04-17 17:35:10 +02:00
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
sh """#!/bin/bash
|
2017-07-11 15:12:03 +02:00
|
|
|
export PATH=./node_modules/.bin:${PATH}
|
2018-04-17 17:35:10 +02:00
|
|
|
$mtaCall
|
2017-07-11 15:12:03 +02:00
|
|
|
"""
|
|
|
|
|
2018-09-04 11:32:54 +02:00
|
|
|
def mtarFilePath = "${mtarFileName}"
|
|
|
|
script?.commonPipelineEnvironment?.setMtarFilePath(mtarFilePath)
|
|
|
|
}
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
}
|