From b3c5cba7070379cd65da684360261e14311ba3b0 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Thu, 8 Nov 2018 09:44:11 +0100 Subject: [PATCH 1/3] Notify about old config framework from neo deploy. --- test/groovy/NeoDeployTest.groovy | 29 +++++++++++++++++++++++++++-- vars/neoDeploy.groovy | 5 +++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/test/groovy/NeoDeployTest.groovy b/test/groovy/NeoDeployTest.groovy index 31f02581f..f5dae61eb 100644 --- a/test/groovy/NeoDeployTest.groovy +++ b/test/groovy/NeoDeployTest.groovy @@ -1,3 +1,4 @@ +import com.sap.piper.Utils import hudson.AbortException import org.junit.rules.TemporaryFolder @@ -6,6 +7,8 @@ import org.junit.BeforeClass import org.junit.ClassRule import org.junit.Ignore +import java.util.Map + import org.hamcrest.BaseMatcher import org.hamcrest.Description import org.jenkinsci.plugins.credentialsbinding.impl.CredentialNotFoundException @@ -81,13 +84,22 @@ class NeoDeployTest extends BasePiperTest { @Test void straightForwardTestConfigViaConfigProperties() { + boolean notifyOldConfigFrameworkUsed = false + nullScript.commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com') nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123') nullScript.commonPipelineEnvironment.configuration = [:] + def utils = new Utils() { + void pushToSWA(Map parameters, Map config) { + notifyOldConfigFrameworkUsed = parameters.stepParam4 + } + } + jsr.step.neoDeploy(script: nullScript, archivePath: archiveName, - neoCredentialsId: 'myCredentialsId' + neoCredentialsId: 'myCredentialsId', + utils: utils ) Assert.assertThat(jscr.shell, @@ -98,14 +110,25 @@ class NeoDeployTest extends BasePiperTest { .hasSingleQuotedOption('user', 'anonymous') .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') .hasDoubleQuotedOption('source', '.*')) + + assert notifyOldConfigFrameworkUsed } @Test void straightForwardTestConfigViaConfiguration() { + boolean notifyOldConfigFrameworkUsed = true + + def utils = new Utils() { + void pushToSWA(Map parameters, Map config) { + notifyOldConfigFrameworkUsed = parameters.stepParam4 + } + } + jsr.step.neoDeploy(script: nullScript, archivePath: archiveName, - neoCredentialsId: 'myCredentialsId' + neoCredentialsId: 'myCredentialsId', + utils: utils, ) Assert.assertThat(jscr.shell, @@ -116,6 +139,8 @@ class NeoDeployTest extends BasePiperTest { .hasSingleQuotedOption('user', 'anonymous') .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') .hasDoubleQuotedOption('source', '.*')) + + assert !notifyOldConfigFrameworkUsed } @Test diff --git a/vars/neoDeploy.groovy b/vars/neoDeploy.groovy index 75cabb565..6f1e3fac3 100644 --- a/vars/neoDeploy.groovy +++ b/vars/neoDeploy.groovy @@ -36,7 +36,7 @@ void call(parameters = [:]) { def script = checkScript(this, parameters) ?: this - def utils = new Utils() + def utils = parameters.utils ?: new Utils() prepareDefaultValues script: script @@ -89,7 +89,8 @@ void call(parameters = [:]) { step: STEP_NAME, stepParam1: configuration.deployMode == 'mta'?'mta':'war', // ['mta', 'warParams', 'warPropertiesFile'] stepParam2: configuration.warAction == 'rolling-update'?'blue-green':'standard', // ['deploy', 'deploy-mta', 'rolling-update'] - stepParam3: parameters?.script == null + stepParam3: parameters?.script == null, + stepParam4: ! stepCompatibilityConfiguration.isEmpty(), ], configuration) def archivePath = configuration.archivePath From 1b8e9d0e30965daa7731fbea62d21cb59b46a223 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Thu, 8 Nov 2018 10:29:30 +0100 Subject: [PATCH 2/3] Emit more explicit warning in case old config framework is is use --- vars/neoDeploy.groovy | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/vars/neoDeploy.groovy b/vars/neoDeploy.groovy index 6f1e3fac3..39be14b86 100644 --- a/vars/neoDeploy.groovy +++ b/vars/neoDeploy.groovy @@ -72,6 +72,23 @@ void call(parameters = [:]) { echo "[WARNING][${STEP_NAME}] Deprecated parameter 'neoCredentialsId' from old configuration framework is used. This will not work anymore in future versions." parameters.put('neoCredentialsId', credId) } + + if(! stepCompatibilityConfiguration.isEmpty()) { + echo "[WARNING][$STEP_NAME] You are using a deprecated configuration framework. This will be removed in " + + 'futureVersions.\nAdd snippet below to \'./pipeline/config.yml\' and remove ' + + 'file \'.pipeline/configuration.properties\'.\n' + + """|steps: + | neoDeploy: + | host: ${stepCompatibilityConfiguration.get('host', '')} + | account: ${stepCompatibilityConfiguration.get('account', '')} + """.stripMargin() + + if(Boolean.getBoolean('com.sap.piper.featureFlag.buildUnstableWhenOldConfigFrameworkIsUsedByNeoDeploy')) { + script.currentBuild.setResult('UNSTABLE') + echo "[WARNING][$STEP_NAME] Build has been set to unstable since old config framework is used." + } + } + // Backward compatibility end // load default & individual configuration From 7063aa12498eaff5eee63cb0b198da41a28703d4 Mon Sep 17 00:00:00 2001 From: Marcus Holl Date: Thu, 8 Nov 2018 10:31:00 +0100 Subject: [PATCH 3/3] set build to unstable in case old config framework is used. protected by feature flag (so we can test it manually already). --- test/groovy/NeoDeployTest.groovy | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/groovy/NeoDeployTest.groovy b/test/groovy/NeoDeployTest.groovy index f5dae61eb..3041998d0 100644 --- a/test/groovy/NeoDeployTest.groovy +++ b/test/groovy/NeoDeployTest.groovy @@ -84,12 +84,15 @@ class NeoDeployTest extends BasePiperTest { @Test void straightForwardTestConfigViaConfigProperties() { + boolean buildStatusHasBeenSet = false boolean notifyOldConfigFrameworkUsed = false nullScript.commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com') nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123') nullScript.commonPipelineEnvironment.configuration = [:] + nullScript.currentBuild = [setResult: {buildStatusHasBeenSet = true}] + def utils = new Utils() { void pushToSWA(Map parameters, Map config) { notifyOldConfigFrameworkUsed = parameters.stepParam4 @@ -111,9 +114,37 @@ class NeoDeployTest extends BasePiperTest { .hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*') .hasDoubleQuotedOption('source', '.*')) + assert !buildStatusHasBeenSet assert notifyOldConfigFrameworkUsed } + @Test + void testConfigViaConfigPropertiesSetsBuildToUnstable() { + + def buildStatus = 'SUCCESS' + + nullScript.commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com') + nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123') + nullScript.commonPipelineEnvironment.configuration = [:] + + nullScript.currentBuild = [setResult: { r -> buildStatus = r}] + + System.setProperty('com.sap.piper.featureFlag.buildUnstableWhenOldConfigFrameworkIsUsedByNeoDeploy', + Boolean.TRUE.toString()) + + try { + jsr.step.neoDeploy(script: nullScript, + archivePath: archiveName, + neoCredentialsId: 'myCredentialsId', + utils: utils + ) + } finally { + System.clearProperty('com.sap.piper.featureFlag.buildUnstableWhenOldConfigFrameworkIsUsedByNeoDeploy') + } + + assert buildStatus == 'UNSTABLE' + } + @Test void straightForwardTestConfigViaConfiguration() {