1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-20 05:19:40 +02:00
sap-jenkins-library/vars/mtaBuild.groovy

109 lines
4.3 KiB
Groovy
Raw Normal View History

import static com.sap.piper.Prerequisites.checkScript
2019-04-01 11:55:39 +02:00
import com.sap.piper.GenerateDocumentation
import com.sap.piper.ConfigurationHelper
import com.sap.piper.MtaUtils
import com.sap.piper.Utils
2017-07-11 15:12:03 +02:00
import groovy.transform.Field
@Field def STEP_NAME = getClass().getName()
2018-02-08 13:18:04 +01:00
@Field Set GENERAL_CONFIG_KEYS = []
@Field Set STEP_CONFIG_KEYS = [
2019-04-01 11:55:39 +02:00
/** The name of the application which is being built. If the parameter has been provided and no `mta.yaml` exists, the `mta.yaml` will be automatically generated using this parameter and the information (`name` and `version`) from `package.json` before the actual build starts.*/
'applicationName',
2019-04-01 11:55:39 +02:00
/**
* The target platform to which the mtar can be deployed.
* @possibleValues 'CF', 'NEO', 'XSA'
*/
'buildTarget',
2019-04-01 11:55:39 +02:00
/** @see dockerExecute */
2018-09-04 11:32:54 +02:00
'dockerImage',
2019-04-01 11:55:39 +02:00
/** The path to the extension descriptor file.*/
'extension',
2019-04-01 11:55:39 +02:00
/**
* The location of the SAP Multitarget Application Archive Builder jar file, including file name and extension.
* If it is not provided, the SAP Multitarget Application Archive Builder is expected on PATH.
*/
'mtaJarLocation'
]
2018-09-04 11:32:54 +02:00
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([
2019-04-01 11:55:39 +02:00
/** @see dockerExecute */
2018-09-04 11:32:54 +02:00
'dockerOptions'
])
2018-02-08 13:18:04 +01:00
2019-04-01 11:55:39 +02:00
/**
* Executes the SAP Multitarget Application Archive Builder to create an mtar archive of the application.
*/
@GenerateDocumentation
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) {
final script = checkScript(this, parameters) ?: this
2018-02-08 13:18:04 +01:00
// load default & individual configuration
Map configuration = ConfigurationHelper.newInstance(this)
.loadStepDefaults()
.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)
.mixin(parameters, PARAMETER_KEYS)
.use()
2018-02-08 13:18:04 +01:00
new Utils().pushToSWA([
step: STEP_NAME,
stepParamKey1: 'scriptMissing',
stepParam1: parameters?.script == null
], 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) {
2018-02-20 13:09:16 +01:00
2018-09-04 11:32:54 +02:00
def mtaYamlName = "mta.yaml"
def applicationName = configuration.applicationName
2018-09-04 11:32:54 +02:00
if (!fileExists(mtaYamlName)) {
if (!applicationName) {
error "'${mtaYamlName}' not found in project sources and 'applicationName' not provided as parameter - cannot generate '${mtaYamlName}' file."
2018-09-04 11:32:54 +02:00
} else {
echo "[INFO] '${mtaYamlName}' file not found in project sources, but application name provided as parameter - generating '${mtaYamlName}' file."
2018-09-04 11:32:54 +02:00
MtaUtils mtaUtils = new MtaUtils(this)
mtaUtils.generateMtaDescriptorFromPackageJson("package.json", mtaYamlName, applicationName)
}
} else {
echo "[INFO] '${mtaYamlName}' file found in project sources."
2018-03-21 12:29:15 +01: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 18:29:41 +01: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"
2019-03-25 14:16:18 +01:00
// If it is not configured, it is expected on the PATH
def mtaJar = 'java -jar '
mtaJar += configuration.mtaJarLocation ?: 'mta.jar'
2018-09-04 11:32:54 +02:00
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-11-12 15:50:38 +01:00
echo "[INFO] Executing mta build call: '${mtaCall}'."
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
"""
script?.commonPipelineEnvironment?.setMtarFilePath(mtarFileName)
2018-09-04 11:32:54 +02:00
}
2017-07-11 15:12:03 +02:00
}
}