2018-02-08 14:18:04 +02:00
|
|
|
import com.sap.piper.ConfigurationLoader
|
|
|
|
import com.sap.piper.ConfigurationMerger
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-02-21 13:48:14 +02:00
|
|
|
import groovy.transform.Field
|
|
|
|
|
|
|
|
@Field def DEFAULT_MTA_JAR_NAME = 'mta.jar'
|
2017-11-24 16:59:34 +02:00
|
|
|
|
2017-07-11 15:12:03 +02:00
|
|
|
def call(Map parameters = [:]) {
|
|
|
|
|
2018-02-08 14:18:04 +02:00
|
|
|
def stepName = 'mtaBuild'
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-02-19 13:53:08 +02:00
|
|
|
Set parameterKeys = [
|
2018-02-08 14:18:04 +02:00
|
|
|
'buildTarget',
|
|
|
|
'mtaJarLocation'
|
|
|
|
]
|
|
|
|
|
2018-02-19 13:53:08 +02:00
|
|
|
Set stepConfigurationKeys = [
|
2018-02-19 20:27:53 +02:00
|
|
|
'buildTarget',
|
2018-02-08 14:18:04 +02:00
|
|
|
'mtaJarLocation'
|
|
|
|
]
|
|
|
|
|
|
|
|
handlePipelineStepErrors (stepName: stepName, stepParameters: parameters) {
|
|
|
|
|
|
|
|
final script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
|
|
|
|
|
|
|
prepareDefaultValues script: script
|
|
|
|
|
|
|
|
final Map configuration = ConfigurationMerger.merge(
|
2018-02-28 12:42:19 +02:00
|
|
|
script, stepName,
|
2018-02-08 14:18:04 +02:00
|
|
|
parameters, parameterKeys,
|
2018-02-28 12:42:19 +02:00
|
|
|
stepConfigurationKeys)
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-02-21 13:48:14 +02:00
|
|
|
MTA_JAR_FILE_VALIDATE: {
|
|
|
|
// same order like inside getMtaJar,
|
|
|
|
def mtaJarLocation = configuration?.mtaJarLocation ?: env?.MTA_JAR_LOCATION
|
2018-02-21 13:52:05 +02:00
|
|
|
def returnCodeLsMtaJar = sh script: "ls ${DEFAULT_MTA_JAR_NAME}", returnStatus:true
|
2018-02-21 13:48:14 +02:00
|
|
|
if(mtaJarLocation || ( !mtaJarLocation && returnCodeLsMtaJar != 0)) {
|
2018-03-08 10:07:25 +02:00
|
|
|
// toolValidate commented since it is does not work in
|
|
|
|
// conjunction with jenkins slaves.
|
|
|
|
// TODO: switch on again when the issue is resolved.
|
|
|
|
// toolValidate tool: 'mta', home: mtaJarLocation
|
|
|
|
echo 'toolValidate (mta) is disabled.'
|
2018-03-06 14:17:20 +02:00
|
|
|
} else {
|
|
|
|
echo "mta toolset (${DEFAULT_MTA_JAR_NAME}) has been found in current working directory. Using this version without further tool validation."
|
2018-02-21 13:48:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-20 14:09:16 +02:00
|
|
|
JAVA_HOME_CHECK : {
|
|
|
|
|
|
|
|
// in case JAVA_HOME is not set, but java is in the path we should not fail
|
|
|
|
// in order to be backward compatible. Before introducing that check here
|
|
|
|
// is worked also in case JAVA_HOME was not set, but java was in the path.
|
|
|
|
// toolValidate works only upon JAVA_HOME and fails in case it is not set.
|
|
|
|
|
|
|
|
def rc = sh script: 'which java' , returnStatus: true
|
|
|
|
if(script.JAVA_HOME || (!script.JAVA_HOME && rc != 0)) {
|
2018-03-08 10:07:25 +02:00
|
|
|
// toolValidate commented since it is does not work in
|
|
|
|
// conjunction with jenkins slaves.
|
|
|
|
// TODO: switch on again when the issue is resolved.
|
|
|
|
echo 'toolValidate (mta) is disabled.'
|
|
|
|
// toolValidate tool: 'java', home: script.JAVA_HOME
|
|
|
|
echo 'toolValidate (java) is disabled.'
|
2018-02-22 12:13:34 +02:00
|
|
|
} else {
|
|
|
|
echo 'Tool validation (java) skipped. JAVA_HOME not set, but java executable in path.'
|
2018-02-20 14:09:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-11 15:12:03 +02:00
|
|
|
def mtaYaml = readYaml file: "${pwd()}/mta.yaml"
|
|
|
|
|
|
|
|
//[Q]: Why not yaml.dump()? [A]: This reformats the whole file.
|
2017-11-13 10:26:34 +02:00
|
|
|
sh "sed -ie \"s/\\\${timestamp}/`date +%Y%m%d%H%M%S`/g\" \"${pwd()}/mta.yaml\""
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
def id = mtaYaml.ID
|
|
|
|
if (!id) {
|
|
|
|
error "Property 'ID' not found in mta.yaml file at: '${pwd()}'"
|
|
|
|
}
|
|
|
|
|
|
|
|
def mtarFileName = "${id}.mtar"
|
|
|
|
|
2018-02-08 14:18:04 +02:00
|
|
|
def mtaJar = getMtaJar(stepName, configuration)
|
|
|
|
def buildTarget = configuration.buildTarget
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
sh """#!/bin/bash
|
|
|
|
export PATH=./node_modules/.bin:${PATH}
|
|
|
|
java -jar ${mtaJar} --mtar ${mtarFileName} --build-target=${buildTarget} build
|
|
|
|
"""
|
|
|
|
|
|
|
|
def mtarFilePath = "${pwd()}/${mtarFileName}"
|
2018-02-08 14:18:04 +02:00
|
|
|
script?.commonPipelineEnvironment?.setMtarFilePath(mtarFilePath)
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
return mtarFilePath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-08 14:18:04 +02:00
|
|
|
private getMtaJar(stepName, configuration) {
|
2018-02-21 13:52:05 +02:00
|
|
|
def mtaJarLocation = DEFAULT_MTA_JAR_NAME //default, maybe it is in current working directory
|
2017-07-11 15:12:03 +02:00
|
|
|
|
2018-02-08 14:18:04 +02:00
|
|
|
if(configuration?.mtaJarLocation){
|
2018-02-23 14:33:14 +02:00
|
|
|
mtaJarLocation = "${configuration.mtaJarLocation}/${DEFAULT_MTA_JAR_NAME}"
|
2018-02-08 14:18:04 +02:00
|
|
|
echo "[$stepName] MTA JAR \"${mtaJarLocation}\" retrieved from configuration."
|
2017-07-11 15:12:03 +02:00
|
|
|
return mtaJarLocation
|
|
|
|
}
|
|
|
|
|
|
|
|
if(env?.MTA_JAR_LOCATION){
|
2018-02-23 14:33:14 +02:00
|
|
|
mtaJarLocation = "${env.MTA_JAR_LOCATION}/${DEFAULT_MTA_JAR_NAME}"
|
2018-02-08 14:18:04 +02:00
|
|
|
echo "[$stepName] MTA JAR \"${mtaJarLocation}\" retrieved from environment."
|
2017-07-11 15:12:03 +02:00
|
|
|
return mtaJarLocation
|
|
|
|
}
|
|
|
|
|
2018-02-08 14:18:04 +02:00
|
|
|
echo "[$stepName] Using MTA JAR from current working directory."
|
2017-07-11 15:12:03 +02:00
|
|
|
return mtaJarLocation
|
|
|
|
}
|
2018-02-08 14:18:04 +02:00
|
|
|
|