1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-04 04:07:16 +02:00

Use mtaBuild step from go (#1536)

Co-authored-by: Your Name <kevin.hudemann@sap.com>
Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
This commit is contained in:
Marcus Holl 2020-05-19 08:51:18 +02:00 committed by GitHub
parent 7f7d0bce89
commit f47f2e6e90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 541 deletions

View File

@ -111,12 +111,12 @@ func MtaBuildCommand() *cobra.Command {
}
func addMtaBuildFlags(cmd *cobra.Command, stepConfig *mtaBuildOptions) {
cmd.Flags().StringVar(&stepConfig.BuildTarget, "buildTarget", os.Getenv("PIPER_buildTarget"), "mtaBuildTool 'classic' only: The target platform to which the mtar can be deployed. Valid values: 'CF', 'NEO', 'XSA'.")
cmd.Flags().StringVar(&stepConfig.BuildTarget, "buildTarget", "NEO", "mtaBuildTool 'classic' only: The target platform to which the mtar can be deployed. Valid values: 'CF', 'NEO', 'XSA'.")
cmd.Flags().StringVar(&stepConfig.MtaBuildTool, "mtaBuildTool", "cloudMbt", "Tool to use when building the MTA. Valid values: 'classic', 'cloudMbt'.")
cmd.Flags().StringVar(&stepConfig.MtarName, "mtarName", os.Getenv("PIPER_mtarName"), "The name of the generated mtar file including its extension.")
cmd.Flags().StringVar(&stepConfig.MtaJarLocation, "mtaJarLocation", os.Getenv("PIPER_mtaJarLocation"), "mtaBuildTool 'classic' only: The location of the SAP Multitarget Application Archive Builder jar file, including file name and extension. If you run on Docker, this must match the location of the jar file in the container as well.")
cmd.Flags().StringVar(&stepConfig.MtaJarLocation, "mtaJarLocation", "/opt/sap/mta/lib/mta.jar", "mtaBuildTool 'classic' only: The location of the SAP Multitarget Application Archive Builder jar file, including file name and extension. If you run on Docker, this must match the location of the jar file in the container as well.")
cmd.Flags().StringVar(&stepConfig.Extensions, "extensions", os.Getenv("PIPER_extensions"), "The path to the extension descriptor file.")
cmd.Flags().StringVar(&stepConfig.Platform, "platform", os.Getenv("PIPER_platform"), "mtaBuildTool 'cloudMbt' only: The target platform to which the mtar can be deployed.")
cmd.Flags().StringVar(&stepConfig.Platform, "platform", "CF", "mtaBuildTool 'cloudMbt' only: The target platform to which the mtar can be deployed.")
cmd.Flags().StringVar(&stepConfig.ApplicationName, "applicationName", os.Getenv("PIPER_applicationName"), "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.")
cmd.Flags().StringVar(&stepConfig.DefaultNpmRegistry, "defaultNpmRegistry", os.Getenv("PIPER_defaultNpmRegistry"), "Url to the npm registry that should be used for installing npm dependencies.")
cmd.Flags().StringVar(&stepConfig.SapNpmRegistry, "sapNpmRegistry", os.Getenv("PIPER_sapNpmRegistry"), "Url to the sap npm registry that should be used for installing npm dependencies prefixed with @sap.")

View File

@ -14,7 +14,7 @@ spec:
- STAGES
- STEPS
mandatory: false
default:
default: NEO
possibleValues:
- CF
- NEO
@ -48,7 +48,7 @@ spec:
- STAGES
- STEPS
mandatory: false
default:
default: /opt/sap/mta/lib/mta.jar
- name: extensions
type: string
description: "The path to the extension descriptor file."
@ -66,7 +66,7 @@ spec:
- STAGES
- STEPS
mandatory: false
default:
default: CF
possibleValues:
- CF
- NEO
@ -125,6 +125,16 @@ spec:
fields:
- name: mtarFilePath
containers:
- name: mta
image: devxci/mbtci
- image: ppiper/mta-archive-builder
conditions:
- conditionRef: strings-equal
params:
- name: mtaBuildTool
value: classic
- image: devxci/mbtci
imagePullPolicy: Always
conditions:
- conditionRef: strings-equal
params:
- name: mtaBuildTool
value: cloudMbt

View File

@ -130,6 +130,7 @@ public class CommonStepsTest extends BasePiperTest{
'mavenBuild', //implementing new golang pattern without fields
'mavenExecute', //implementing new golang pattern without fields
'mavenExecuteStaticCodeChecks', //implementing new golang pattern without fields
'mtaBuild', //implementing new golang pattern without fields
'nexusUpload', //implementing new golang pattern without fields
'piperPipelineStageArtifactDeployment', //stage without step flags
'abapEnvironmentRunATCCheck', //implementing new golang pattern without fields

View File

@ -72,7 +72,7 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
@Before
void setup() {
//
// needed since we have dockerExecute inside mtaBuild
// needed since we have dockerExecute inside neoDeploy
JenkinsUtils.metaClass.static.isPluginActive = {def s -> false}
//
@ -81,30 +81,19 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
it ->
// called inside mtaBuild, this file contains build config
it == 'mta.yaml' ||
// called inside neo deploy, this file gets deployed
it == 'test.mtar'
})
helper.registerAllowedMethod("deleteDir",[], null)
//
// the properties below we read out of the yaml file
readYamlRule.registerYaml('mta.yaml', ('''
|ID : "test"
|PATH : "."
|''' as CharSequence).stripMargin())
//
// we need the path variable since we extend the path in the mtaBuild step. In order
// to be able to extend the path we have to have some initial value.
binding.setVariable('PATH', '/usr/bin')
binding.setVariable('scm', null)
helper.registerAllowedMethod('pwd', [], { return "./" })
helper.registerAllowedMethod('mtaBuild', [Map], {
m -> m.script.commonPipelineEnvironment.mtarFilePath = 'test.mtar'
})
}
@Test
@ -126,17 +115,10 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
platform: 'NEO',
)
//
// the mta build call:
assertThat(shellRule.shell, hasItem(
allOf( containsString('mbt build'),
containsString('--mtar test.mtar'),
containsString('--platform NEO'),
containsString('--target ./'))))
//
// the deployable is exchanged between the involved steps via this property:
// From the presence of this value we can conclude that mtaBuild has been called
// this value is set on the commonPipelineEnvironment in the corresponding mock.
assertThat(nullScript.commonPipelineEnvironment.getMtarFilePath(), is(equalTo('test.mtar')))
//

View File

@ -22,339 +22,44 @@ import static org.hamcrest.Matchers.hasItem
public class MtaBuildTest extends BasePiperTest {
private ExpectedException thrown = new ExpectedException()
private JenkinsLoggingRule loggingRule = new JenkinsLoggingRule(this)
private JenkinsShellCallRule shellRule = new JenkinsShellCallRule(this)
private JenkinsDockerExecuteRule dockerExecuteRule = new JenkinsDockerExecuteRule(this)
private JenkinsStepRule stepRule = new JenkinsStepRule(this)
private JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule(this).registerYaml('mta.yaml', defaultMtaYaml() )
private JenkinsWriteFileRule writeFileRule = new JenkinsWriteFileRule(this)
private JenkinsReadYamlRule readYamlRule = new JenkinsReadYamlRule(this)
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(readYamlRule)
.around(thrown)
.around(loggingRule)
.around(shellRule)
.around(dockerExecuteRule)
.around(stepRule)
.around(writeFileRule)
@Before
void init() {
helper.registerAllowedMethod('fileExists', [String], { s -> s == 'mta.yaml' })
helper.registerAllowedMethod('httpRequest', [String.class], { s -> new SettingsStub()})
shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*\\$MTA_JAR_LOCATION.*', '')
shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*\\$JAVA_HOME.*', '')
shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*which java.*', 0)
shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*java -version.*', '''openjdk version \"1.8.0_121\"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-1~bpo8+1-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)''')
shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.*mta\\.jar -v.*', '1.0.6')
}
.around(readYamlRule)
@Test
void environmentPathTest() {
void testCallGoWrapper() {
def calledWithParameters,
calledWithStepName,
calledWithMetadata,
calledWithCredentials
helper.registerAllowedMethod(
'piperExecuteBin',
[Map, String, String, List],
{
params, stepName, metaData, creds ->
calledWithParameters = params
calledWithStepName = stepName
calledWithMetadata = metaData
calledWithCredentials = creds
}
)
stepRule.step.mtaBuild(script: nullScript, buildTarget: 'CF')
assert calledWithParameters.size() == 2
assert calledWithParameters.script == nullScript
assert calledWithParameters.buildTarget == 'CF'
assert calledWithStepName == 'mtaBuild'
assert calledWithMetadata == 'metadata/mtaBuild.yaml'
assert calledWithCredentials.isEmpty()
stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO')
assert shellRule.shell.find { c -> c.contains('PATH=./node_modules/.bin:$PATH')}
}
@Test
void sedTest() {
stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO')
assert shellRule.shell.find { c -> c =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" "mta.yaml"$/}
}
@Test
void mtarFilePathFromCommonPipelineEnvironmentTest() {
stepRule.step.mtaBuild(script: nullScript,
buildTarget: 'NEO')
def mtarFilePath = nullScript.commonPipelineEnvironment.getMtarFilePath()
assert mtarFilePath == "com.mycompany.northwind.mtar"
}
@Test
void mtaJarLocationAsParameterTest() {
stepRule.step.mtaBuild(script: nullScript, mtaBuildTool: 'classic', mtaJarLocation: '/mylocation/mta/mta.jar', buildTarget: 'NEO')
assert shellRule.shell.find { c -> c.contains('-jar /mylocation/mta/mta.jar --mtar')}
}
@Test
void noMtaPresentTest() {
helper.registerAllowedMethod('fileExists', [String], { false })
thrown.expect(AbortException)
thrown.expectMessage('\'mta.yaml\' not found in project sources and \'applicationName\' not provided as parameter ' +
'- cannot generate \'mta.yaml\' file.')
stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO')
}
@Test
void badMtaTest() {
thrown.expect(ParserException)
thrown.expectMessage('while parsing a block mapping')
readYamlRule.registerYaml('mta.yaml', badMtaYaml())
stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO')
}
@Test
void noIdInMtaTest() {
thrown.expect(AbortException)
thrown.expectMessage("Property 'ID' not found in mta.yaml file.")
readYamlRule.registerYaml('mta.yaml', noIdMtaYaml() )
stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO')
}
@Test
void mtaJarLocationFromCustomStepConfigurationTest() {
nullScript.commonPipelineEnvironment.configuration = [steps:[mtaBuild:[mtaJarLocation: '/config/mta/mta.jar']]]
stepRule.step.mtaBuild(script: nullScript, mtaBuildTool: 'classic',
buildTarget: 'NEO')
assert shellRule.shell.find(){ c -> c.contains('java -jar /config/mta/mta.jar --mtar')}
}
@Test
void mtaJarLocationFromDefaultStepConfigurationTest() {
stepRule.step.mtaBuild(script: nullScript, mtaBuildTool: 'classic',
buildTarget: 'NEO')
assert shellRule.shell.find(){ c -> c.contains('java -jar /opt/sap/mta/lib/mta.jar --mtar')}
}
@Test
void buildTargetFromParametersTest() {
stepRule.step.mtaBuild(script: nullScript, mtaBuildTool: 'classic', buildTarget: 'NEO')
assert shellRule.shell.find { c -> c.contains('java -jar /opt/sap/mta/lib/mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')}
}
@Test
void buildTargetFromCustomStepConfigurationTest() {
nullScript.commonPipelineEnvironment.configuration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
stepRule.step.mtaBuild(script: nullScript, mtaBuildTool: 'classic')
assert shellRule.shell.find(){ c -> c.contains('java -jar /opt/sap/mta/lib/mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')}
}
@Test
void dockerFromCustomStepConfigurationTest() {
def expectedImage = 'image:test'
def expectedEnvVars = ['env1': 'value1', 'env2': 'value2']
def expectedOptions = '--opt1=val1 --opt2=val2 --opt3'
def expectedWorkspace = '-w /path/to/workspace'
nullScript.commonPipelineEnvironment.configuration = [steps:[mtaBuild:[
dockerImage: expectedImage,
dockerOptions: expectedOptions,
dockerEnvVars: expectedEnvVars,
dockerWorkspace: expectedWorkspace
]]]
stepRule.step.mtaBuild(script: nullScript)
assert expectedImage == dockerExecuteRule.dockerParams.dockerImage
assert expectedOptions == dockerExecuteRule.dockerParams.dockerOptions
assert expectedEnvVars.equals(dockerExecuteRule.dockerParams.dockerEnvVars)
assert expectedWorkspace == dockerExecuteRule.dockerParams.dockerWorkspace
}
@Test
void canConfigureDockerImage() {
stepRule.step.mtaBuild(script: nullScript, dockerImage: 'mta-docker-image:latest')
assert 'mta-docker-image:latest' == dockerExecuteRule.dockerParams.dockerImage
}
@Test
void canConfigureDockerOptions() {
stepRule.step.mtaBuild(script: nullScript, dockerOptions: 'something')
assert 'something' == dockerExecuteRule.dockerParams.dockerOptions
}
@Test
void canConfigureMavenUserSettings() {
stepRule.step.mtaBuild(script: nullScript, projectSettingsFile: 'settings.xml')
assert shellRule.shell.find(){ c -> c.contains('cp settings.xml $HOME/.m2/settings.xml')}
}
@Test
void canConfigureMavenUserSettingsFromRemoteSource() {
stepRule.step.mtaBuild(script: nullScript, projectSettingsFile: 'https://some.host/my-settings.xml')
assert shellRule.shell.find(){ c -> c.contains('cp project-settings.xml $HOME/.m2/settings.xml')}
}
@Test
void canConfigureMavenGlobalSettings() {
stepRule.step.mtaBuild(script: nullScript, globalSettingsFile: 'settings.xml')
assert shellRule.shell.find(){ c -> c.contains('cp settings.xml $M2_HOME/conf/settings.xml')}
}
@Test
void canConfigureNpmRegistry() {
stepRule.step.mtaBuild(script: nullScript, defaultNpmRegistry: 'myNpmRegistry.com')
assert shellRule.shell.find(){ c -> c.contains('npm config set registry myNpmRegistry.com')}
}
@Test
void canConfigureMavenGlobalSettingsFromRemoteSource() {
stepRule.step.mtaBuild(script: nullScript, globalSettingsFile: 'https://some.host/my-settings.xml')
assert shellRule.shell.find(){ c -> c.contains('cp global-settings.xml $M2_HOME/conf/settings.xml')}
}
@Test
void buildTargetFromDefaultStepConfigurationTest() {
nullScript.commonPipelineEnvironment.defaultConfiguration = [steps:[mtaBuild:[buildTarget: 'NEO']]]
stepRule.step.mtaBuild(script: nullScript, mtaBuildTool: 'classic',)
assert shellRule.shell.find { c -> c.contains('java -jar /opt/sap/mta/lib/mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO build')}
}
@Test
void extensionFromParametersTest() {
stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO', mtaBuildTool: 'classic', extension: 'param_extension')
assert shellRule.shell.find { c -> c.contains('java -jar /opt/sap/mta/lib/mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO --extension=param_extension build')}
}
@Test
void extensionFromCustomStepConfigurationTest() {
nullScript.commonPipelineEnvironment.configuration = [steps:[mtaBuild:[buildTarget: 'NEO', extension: 'config_extension']]]
stepRule.step.mtaBuild(script: nullScript, mtaBuildTool: 'classic',)
assert shellRule.shell.find(){ c -> c.contains('java -jar /opt/sap/mta/lib/mta.jar --mtar com.mycompany.northwind.mtar --build-target=NEO --extension=config_extension build')}
}
@Test
void canConfigureMTARName() {
stepRule.step.mtaBuild(script: nullScript, mtarName: 'custom.name.mtar')
assert shellRule.shell.find(){ c -> c.contains('--mtar custom.name.mtar')}
}
@Test
void testCloudMbt() {
nullScript.commonPipelineEnvironment.configuration = [steps:[mtaBuild:[mtaBuildTool: 'cloudMbt']]]
stepRule.step.mtaBuild(script: nullScript)
assertThat(shellRule.shell, hasItem(containsString('mbt build')))
assertThat(shellRule.shell, hasItem(containsString('--platform cf')))
assertThat(shellRule.shell, hasItem(containsString('--target ./')))
assertThat(shellRule.shell, hasItem(containsString('--mtar com.mycompany.northwind.mtar')))
}
private static defaultMtaYaml() {
return '''
_schema-version: "2.0.0"
ID: "com.mycompany.northwind"
version: 1.0.0
parameters:
hcp-deployer-version: "1.0.0"
modules:
- name: "fiorinorthwind"
type: html5
path: .
parameters:
version: 1.0.0-${timestamp}
build-parameters:
builder: grunt
build-result: dist
'''
}
private badMtaYaml() {
return '''
_schema-version: "2.0.0
ID: "com.mycompany.northwind"
version: 1.0.0
parameters:
hcp-deployer-version: "1.0.0"
modules:
- name: "fiorinorthwind"
type: html5
path: .
parameters:
version: 1.0.0-${timestamp}
build-parameters:
builder: grunt
build-result: dist
'''
}
private noIdMtaYaml() {
return '''
_schema-version: "2.0.0"
version: 1.0.0
parameters:
hcp-deployer-version: "1.0.0"
modules:
- name: "fiorinorthwind"
type: html5
path: .
parameters:
version: 1.0.0-${timestamp}
build-parameters:
builder: grunt
build-result: dist
'''
}
class SettingsStub {
String getContent() {
return "<xml>sometext</xml>"
}
}
}

View File

@ -1,189 +1,13 @@
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.GenerateDocumentation
import com.sap.piper.ConfigurationHelper
import com.sap.piper.MtaUtils
import com.sap.piper.Utils
import groovy.transform.Field
import static com.sap.piper.Prerequisites.checkScript
import com.sap.piper.DownloadCacheUtils
import static com.sap.piper.Utils.downloadSettingsFromUrl
@Field String STEP_NAME = getClass().getName()
@Field String METADATA_FILE = 'metadata/mtaBuild.yaml'
@Field def STEP_NAME = getClass().getName()
@Field Set GENERAL_CONFIG_KEYS = []
@Field Set STEP_CONFIG_KEYS = [
/** 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',
/**
* mtaBuildTool classic only: The target platform to which the mtar can be deployed.
* @possibleValues 'CF', 'NEO', 'XSA'
*/
'buildTarget',
/**
* Tool to use when building the MTA
* @possibleValues 'classic', 'cloudMbt'
*/
'mtaBuildTool',
/** @see dockerExecute */
'dockerImage',
/** @see dockerExecute */
'dockerEnvVars',
/** @see dockerExecute */
'dockerOptions',
/** @see dockerExecute */
'dockerWorkspace',
/** The path to the extension descriptor file.*/
'extension',
/**
* The location of the SAP Multitarget Application Archive Builder jar file, including file name and extension.
* If you run on Docker, this must match the location of the jar file in the container as well.
*/
'mtaJarLocation',
/** Path or url to the mvn settings file that should be used as global settings file.*/
'globalSettingsFile',
/** The name of the generated mtar file including its extension. */
'mtarName',
/**
* mtaBuildTool cloudMbt only: The target platform to which the mtar can be deployed.
* @possibleValues 'CF', 'NEO', 'XSA'
*/
'platform',
/** Path or url to the mvn settings file that should be used as project settings file.*/
'projectSettingsFile',
/** Url to the npm registry that should be used for installing npm dependencies.*/
'defaultNpmRegistry',
/** Url to the sap npm registry that should be used for installing npm dependencies prefixed with @sap.*/
'sapNpmRegistry'
]
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
/**
* Executes the SAP Multitarget Application Archive Builder to create an mtar archive of the application.
*/
@GenerateDocumentation
void call(Map parameters = [:]) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
final script = checkScript(this, parameters) ?: this
parameters = DownloadCacheUtils.injectDownloadCacheInMavenParameters(script, parameters)
final script = checkScript(this, parameters) ?: this
// load default & individual configuration
Map configuration = ConfigurationHelper.newInstance(this)
.loadStepDefaults()
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName ?: env.STAGE_NAME, STEP_CONFIG_KEYS)
.mixin(parameters, PARAMETER_KEYS)
.dependingOn('mtaBuildTool').mixin('dockerImage')
.use()
new Utils().pushToSWA([
step: STEP_NAME,
stepParamKey1: 'scriptMissing',
stepParam1: parameters?.script == null
], configuration)
dockerExecute(
script: script,
dockerImage: configuration.dockerImage,
dockerEnvVars: configuration.dockerEnvVars,
dockerOptions: configuration.dockerOptions,
dockerWorkspace: configuration.dockerWorkspace
) {
String projectSettingsFile = configuration.projectSettingsFile?.trim()
if (projectSettingsFile) {
if (projectSettingsFile.startsWith("http")) {
projectSettingsFile = downloadSettingsFromUrl(this, projectSettingsFile, 'project-settings.xml')
}
sh 'mkdir -p $HOME/.m2'
sh "cp ${projectSettingsFile} \$HOME/.m2/settings.xml"
}
String globalSettingsFile = configuration.globalSettingsFile?.trim()
if (globalSettingsFile) {
if (globalSettingsFile.startsWith("http")) {
globalSettingsFile = downloadSettingsFromUrl(this, globalSettingsFile, 'global-settings.xml')
}
sh "cp ${globalSettingsFile} \$M2_HOME/conf/settings.xml"
}
String defaultNpmRegistry = configuration.defaultNpmRegistry?.trim()
if (defaultNpmRegistry) {
sh "npm config set registry ${defaultNpmRegistry}"
}
String sapNpmRegistry = configuration.sapNpmRegistry?.trim()
if (sapNpmRegistry) {
sh "npm config set @sap:registry ${sapNpmRegistry}"
}
def mtaYamlName = "mta.yaml"
def applicationName = configuration.applicationName
if (!fileExists(mtaYamlName)) {
if (!applicationName) {
error "'${mtaYamlName}' not found in project sources and 'applicationName' not provided as parameter - cannot generate '${mtaYamlName}' file."
} else {
echo "[INFO] '${mtaYamlName}' file not found in project sources, but application name provided as parameter - generating '${mtaYamlName}' file."
MtaUtils mtaUtils = new MtaUtils(this)
mtaUtils.generateMtaDescriptorFromPackageJson("package.json", mtaYamlName, applicationName)
}
} else {
echo "[INFO] '${mtaYamlName}' file found in project sources."
}
//[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}\""
def mtaCall
def options = []
String mtarName = configuration.mtarName?.trim()
if (!mtarName) {
def mtaId = getMtaId(mtaYamlName)
mtarName = "${mtaId}.mtar"
}
options.push("--mtar ${mtarName}")
switch(configuration.mtaBuildTool) {
case 'classic':
// If it is not configured, it is expected on the PATH
def mtaJar = configuration.mtaJarLocation ?: 'mta.jar'
options.push("--build-target=${configuration.buildTarget}")
if (configuration.extension) options.push("--extension=${configuration.extension}")
mtaCall = "java -jar ${mtaJar} ${options.join(' ')} build"
break
case 'cloudMbt':
options.push("--platform ${configuration.platform}")
options.push("--target ./")
if (configuration.extension) options.push("--extensions=${configuration.extension}")
mtaCall = "mbt build ${options.join(' ')}"
break
default:
error "[ERROR][${STEP_NAME}] MTA build tool '${configuration.mtaBuildTool}' not supported!"
}
echo "[INFO] Executing mta build call: '${mtaCall}'."
//[Q]: Why extending the path? [A]: To be sure e.g. grunt can be found
//[Q]: Why escaping \$PATH ? [A]: We want to extend the PATH variable in e.g. the container and not substituting it with the Jenkins environment when using ${PATH}
sh """#!/bin/bash
export PATH=./node_modules/.bin:\$PATH
$mtaCall
"""
script?.commonPipelineEnvironment?.setMtarFilePath("${mtarName}")
}
}
}
def String getMtaId(String fileName){
def mtaYaml = readYaml file: fileName
if (!mtaYaml.ID) {
error "Property 'ID' not found in ${fileName} file."
}
return mtaYaml.ID
piperExecuteBin(parameters, STEP_NAME, METADATA_FILE, [])
}