From 7feaa368687e9367d93bdc56b741fb69fa5732f7 Mon Sep 17 00:00:00 2001 From: Prashanth Madarapu Date: Fri, 6 Dec 2019 12:18:20 +0530 Subject: [PATCH] feat(mta): allow configuration of filename for generated mtar (#1030) * Add new config mtarName for mtaBuild step * Remove unnecessary whitespace changes in unit test * Sort new config & avoid file operation when this config provided * Modify the test to take the custom name without extension * Update new config documentation Co-Authored-By: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * custom mta name should be given with mtar extension * Updated the config documentation --- test/groovy/MtaBuildTest.groovy | 8 ++++++++ vars/mtaBuild.groovy | 14 ++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/test/groovy/MtaBuildTest.groovy b/test/groovy/MtaBuildTest.groovy index ffa6ea72a..c5fb48652 100644 --- a/test/groovy/MtaBuildTest.groovy +++ b/test/groovy/MtaBuildTest.groovy @@ -270,6 +270,14 @@ public class MtaBuildTest extends BasePiperTest { 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']]] diff --git a/vars/mtaBuild.groovy b/vars/mtaBuild.groovy index 442e7ab20..c6d25d76d 100644 --- a/vars/mtaBuild.groovy +++ b/vars/mtaBuild.groovy @@ -41,6 +41,8 @@ import static com.sap.piper.Utils.downloadSettingsFromUrl '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' @@ -127,11 +129,15 @@ void call(Map parameters = [:]) { //[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 id = getMtaId(mtaYamlName) - def mtaCall def options = [] - options.push("--mtar ${id}.mtar") + + String mtarName = configuration.mtarName?.trim() + if (!mtarName) { + def mtaId = getMtaId(mtaYamlName) + mtarName = "${mtaId}.mtar" + } + options.push("--mtar ${mtarName}") switch(configuration.mtaBuildTool) { case 'classic': @@ -160,7 +166,7 @@ void call(Map parameters = [:]) { $mtaCall """ - script?.commonPipelineEnvironment?.setMtarFilePath("${id}.mtar") + script?.commonPipelineEnvironment?.setMtarFilePath("${mtarName}") } } }