From 1b95951eb20cc5c740e2302dec03e589eb23fd41 Mon Sep 17 00:00:00 2001 From: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> Date: Wed, 4 Dec 2019 13:24:23 +0100 Subject: [PATCH] fix(mta): create MTAR in project root when using Cloud MBT (#1024) * fix(mta): generate MTAR to the project root when Cloud MBT is used fixes #1023 * add test case --- test/groovy/MtaBuildTest.groovy | 27 +++++++++++++++------------ vars/mtaBuild.groovy | 2 +- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/test/groovy/MtaBuildTest.groovy b/test/groovy/MtaBuildTest.groovy index 4d6194409..ffa6ea72a 100644 --- a/test/groovy/MtaBuildTest.groovy +++ b/test/groovy/MtaBuildTest.groovy @@ -16,6 +16,10 @@ import util.JenkinsStepRule import util.JenkinsWriteFileRule import util.Rules +import static org.junit.Assert.assertThat +import static org.hamcrest.Matchers.containsString +import static org.hamcrest.Matchers.hasItem + public class MtaBuildTest extends BasePiperTest { private ExpectedException thrown = new ExpectedException() @@ -54,7 +58,6 @@ public class MtaBuildTest extends BasePiperTest { } - @Test void environmentPathTest() { @@ -63,7 +66,6 @@ public class MtaBuildTest extends BasePiperTest { assert shellRule.shell.find { c -> c.contains('PATH=./node_modules/.bin:$PATH')} } - @Test void sedTest() { @@ -72,7 +74,6 @@ public class MtaBuildTest extends BasePiperTest { assert shellRule.shell.find { c -> c =~ /sed -ie "s\/\\\$\{timestamp\}\/`date \+%Y%m%d%H%M%S`\/g" "mta.yaml"$/} } - @Test void mtarFilePathFromCommonPipelineEnvironmentTest() { @@ -92,7 +93,6 @@ public class MtaBuildTest extends BasePiperTest { assert shellRule.shell.find { c -> c.contains('-jar /mylocation/mta/mta.jar --mtar')} } - @Test void noMtaPresentTest() { helper.registerAllowedMethod('fileExists', [String], { false }) @@ -103,7 +103,6 @@ public class MtaBuildTest extends BasePiperTest { stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO') } - @Test void badMtaTest() { @@ -115,7 +114,6 @@ public class MtaBuildTest extends BasePiperTest { stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO') } - @Test void noIdInMtaTest() { @@ -127,7 +125,6 @@ public class MtaBuildTest extends BasePiperTest { stepRule.step.mtaBuild(script: nullScript, buildTarget: 'NEO') } - @Test void mtaJarLocationFromCustomStepConfigurationTest() { @@ -139,7 +136,6 @@ public class MtaBuildTest extends BasePiperTest { assert shellRule.shell.find(){ c -> c.contains('java -jar /config/mta/mta.jar --mtar')} } - @Test void mtaJarLocationFromDefaultStepConfigurationTest() { @@ -149,7 +145,6 @@ public class MtaBuildTest extends BasePiperTest { assert shellRule.shell.find(){ c -> c.contains('java -jar /opt/sap/mta/lib/mta.jar --mtar')} } - @Test void buildTargetFromParametersTest() { @@ -158,7 +153,6 @@ 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 build')} } - @Test void buildTargetFromCustomStepConfigurationTest() { @@ -258,7 +252,6 @@ 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 build')} } - @Test void extensionFromParametersTest() { @@ -267,7 +260,6 @@ 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=param_extension build')} } - @Test void extensionFromCustomStepConfigurationTest() { @@ -278,6 +270,17 @@ 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 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 ''' diff --git a/vars/mtaBuild.groovy b/vars/mtaBuild.groovy index a301feaf4..442e7ab20 100644 --- a/vars/mtaBuild.groovy +++ b/vars/mtaBuild.groovy @@ -133,7 +133,6 @@ void call(Map parameters = [:]) { def options = [] options.push("--mtar ${id}.mtar") - switch(configuration.mtaBuildTool) { case 'classic': // If it is not configured, it is expected on the PATH @@ -144,6 +143,7 @@ void call(Map parameters = [:]) { 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