mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
Introduce new config framework into neoDeploy
This commit is contained in:
parent
2001816318
commit
1ff46861e0
@ -8,4 +8,8 @@ steps:
|
||||
dockerImage: 'maven:3.5-jdk-7'
|
||||
influxWriteData:
|
||||
influxServer: 'jenkins'
|
||||
|
||||
neoDeploy:
|
||||
deployMode: 'mta'
|
||||
warAction: 'deploy'
|
||||
vmSize: 'lite'
|
||||
neoCredentialsId: 'CI_CREDENTIALS_ID'
|
||||
|
@ -1,4 +1,5 @@
|
||||
import hudson.AbortException
|
||||
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
@ -76,7 +77,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
|
||||
|
||||
@Test
|
||||
void straightForwardTest() {
|
||||
void straightForwardTestConfigViaConfigProperties() {
|
||||
|
||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||
|
||||
@ -96,6 +97,53 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void straightForwardTestConfigViaConfiguration() {
|
||||
|
||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
|
||||
cpe.configuration.put('steps', [neoDeploy: [host: 'test.deploy.host.com',
|
||||
account: 'trialuser123']])
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void straightForwardTestConfigViaConfigurationAndViaConfigProperties() {
|
||||
|
||||
//configuration via configurationFramekwork superseds.
|
||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
|
||||
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
|
||||
cpe.configuration.put('steps', [neoDeploy: [host: 'configuration-frwk.deploy.host.com',
|
||||
account: 'configurationFrwkUser123']])
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'configuration-frwk\.deploy\.host\.com' --account 'configurationFrwkUser123' --synchronous/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void badCredentialsIdTest() {
|
||||
@ -105,6 +153,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
|
||||
thrown.expect(MissingPropertyException)
|
||||
thrown.expectMessage('No such property: username')
|
||||
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
@ -169,9 +218,6 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/etc\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous.*/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/etc/neo/tools/neo.sh\" retrieved from parameters.")
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -179,7 +225,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
void archiveNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR archivePath')
|
||||
thrown.expectMessage('Archive path not configured (parameter "archivePath").')
|
||||
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
@ -192,7 +238,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
void wrongArchivePathProvidedTest() {
|
||||
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Archive cannot be found with parameter archivePath: '")
|
||||
thrown.expectMessage("Archive cannot be found")
|
||||
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
@ -208,7 +254,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR deployHost')
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR host')
|
||||
|
||||
neoDeployScript.call(archivePath: archiveName)
|
||||
}
|
||||
|
@ -1,72 +1,137 @@
|
||||
import com.sap.piper.Utils
|
||||
|
||||
import com.sap.piper.ConfigurationLoader
|
||||
import com.sap.piper.ConfigurationMerger
|
||||
import com.sap.piper.ConfigurationType
|
||||
|
||||
def call(parameters = [:]) {
|
||||
|
||||
handlePipelineStepErrors (stepName: 'neoDeploy', stepParameters: parameters) {
|
||||
def stepName = 'neoDeploy'
|
||||
|
||||
def utils = new Utils()
|
||||
List parameterKeys = [
|
||||
'applicationName',
|
||||
'archivePath',
|
||||
'account',
|
||||
'deployMode',
|
||||
'dockerEnvVars',
|
||||
'dockerImage',
|
||||
'dockerOptions',
|
||||
'host',
|
||||
'neoCredentialsId',
|
||||
'neoHome',
|
||||
'propertiesFile',
|
||||
'runtime',
|
||||
'runtimeVersion',
|
||||
'vmSize',
|
||||
'warAction'
|
||||
]
|
||||
|
||||
List stepConfigurationKeys = [
|
||||
'account',
|
||||
'dockerEnvVars',
|
||||
'dockerImage',
|
||||
'dockerOptions',
|
||||
'host',
|
||||
'neoCredentialsId',
|
||||
'neoHome'
|
||||
]
|
||||
|
||||
handlePipelineStepErrors (stepName: stepName, stepParameters: parameters) {
|
||||
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
def archivePath = utils.getMandatoryParameter(parameters, 'archivePath', null)
|
||||
if (!fileExists(archivePath)){
|
||||
error "Archive cannot be found with parameter archivePath: '${archivePath}'."
|
||||
def utils = new Utils()
|
||||
|
||||
prepareDefaultValues script: script
|
||||
|
||||
final Map stepConfiguration = [:]
|
||||
|
||||
// Backward compatibility: ensure old configuration is taken into account
|
||||
// The old configuration in not stage / step specific
|
||||
|
||||
def defaultDeployHost = script.commonPipelineEnvironment.getConfigProperty('DEPLOY_HOST')
|
||||
if(defaultDeployHost) {
|
||||
echo "[WARNING][${stepName}] A deprecated configuration framework is used for configuring parameter 'DEPLOY_HOST'. This configuration framework will be removed in future versions."
|
||||
stepConfiguration.put('host', defaultDeployHost)
|
||||
}
|
||||
|
||||
def deployMode = utils.getMandatoryParameter(parameters, 'deployMode', 'mta')
|
||||
def defaultDeployAccount = script.commonPipelineEnvironment.getConfigProperty('CI_DEPLOY_ACCOUNT')
|
||||
if(defaultDeployAccount) {
|
||||
echo "[WARNING][${stepName}] A deprecated configuration framework is used for configuring parameter 'DEPLOY_ACCOUNT'. This configuration framekwork will be removed in future versions."
|
||||
stepConfiguration.put('account', defaultDeployAccount)
|
||||
}
|
||||
|
||||
if(parameters.DEPLOY_HOST && !parameters.host) {
|
||||
echo "[WARNING][${stepName}] Deprecated parameter 'DEPLOY_HOST' is used. This will not work anymore in future versions. Use parameter 'host' instead."
|
||||
parameters.put('host', parameters.DEPLOY_HOST)
|
||||
}
|
||||
|
||||
if(parameters.CI_DEPLOY_ACCOUNT && !parameters.account) {
|
||||
echo "[WARNING][${stepName}] Deprecated parameter 'CI_DEPLOY_ACCOUNT' is used. This will not work anymore in future versions. Use parameter 'account' instead."
|
||||
parameters.put('account', parameters.CI_DEPLOY_ACCOUNT)
|
||||
}
|
||||
|
||||
// Backward compatibility end
|
||||
|
||||
stepConfiguration.putAll(ConfigurationLoader.stepConfiguration(script, stepName))
|
||||
|
||||
Map configuration = ConfigurationMerger.merge(parameters, parameterKeys,
|
||||
stepConfiguration, stepConfigurationKeys,
|
||||
ConfigurationLoader.defaultStepConfiguration(script, stepName))
|
||||
|
||||
def archivePath = configuration.archivePath
|
||||
if(archivePath?.trim()) {
|
||||
if (!fileExists(archivePath)) {
|
||||
error "Archive cannot be found with parameter archivePath: '${archivePath}'."
|
||||
}
|
||||
} else {
|
||||
error "Archive path not configured (parameter \"archivePath\")."
|
||||
}
|
||||
|
||||
def deployHost
|
||||
def deployAccount
|
||||
def credentialsId = configuration.get('neoCredentialsId', '')
|
||||
def deployMode = configuration.deployMode
|
||||
def warAction
|
||||
def propertiesFile
|
||||
def applicationName
|
||||
def runtime
|
||||
def runtimeVersion
|
||||
def vmSize
|
||||
|
||||
if (deployMode != 'mta' && deployMode != 'warParams' && deployMode != 'warPropertiesFile') {
|
||||
throw new Exception("[neoDeploy] Invalid deployMode = '${deployMode}'. Valid 'deployMode' values are: 'mta', 'warParams' and 'warPropertiesFile'")
|
||||
}
|
||||
|
||||
def propertiesFile
|
||||
def warAction
|
||||
if (deployMode == 'warPropertiesFile' || deployMode == 'warParams') {
|
||||
warAction = utils.getMandatoryParameter(parameters, 'warAction', 'deploy')
|
||||
warAction = utils.getMandatoryParameter(configuration, 'warAction')
|
||||
if (warAction != 'deploy' && warAction != 'rolling-update') {
|
||||
throw new Exception("[neoDeploy] Invalid warAction = '${warAction}'. Valid 'warAction' values are: 'deploy' and 'rolling-update'.")
|
||||
}
|
||||
}
|
||||
|
||||
if (deployMode == 'warPropertiesFile') {
|
||||
propertiesFile = utils.getMandatoryParameter(parameters, 'propertiesFile', null)
|
||||
propertiesFile = utils.getMandatoryParameter(configuration, 'propertiesFile')
|
||||
if (!fileExists(propertiesFile)){
|
||||
error "Properties file cannot be found with parameter propertiesFile: '${propertiesFile}'."
|
||||
}
|
||||
}
|
||||
|
||||
def applicationName
|
||||
def runtime
|
||||
def runtimeVersion
|
||||
def vmSize
|
||||
if (deployMode == 'warParams') {
|
||||
applicationName = utils.getMandatoryParameter(parameters, 'applicationName', null)
|
||||
runtime = utils.getMandatoryParameter(parameters, 'runtime', null)
|
||||
runtimeVersion = utils.getMandatoryParameter(parameters, 'runtimeVersion', null)
|
||||
vmSize = utils.getMandatoryParameter(parameters, 'vmSize', 'lite')
|
||||
applicationName = utils.getMandatoryParameter(configuration, 'applicationName')
|
||||
runtime = utils.getMandatoryParameter(configuration, 'runtime')
|
||||
runtimeVersion = utils.getMandatoryParameter(configuration, 'runtimeVersion')
|
||||
vmSize = configuration.vmSize
|
||||
if (vmSize != 'lite' && vmSize !='pro' && vmSize != 'prem' && vmSize != 'prem-plus') {
|
||||
throw new Exception("[neoDeploy] Invalid vmSize = '${vmSize}'. Valid 'vmSize' values are: 'lite', 'pro', 'prem' and 'prem-plus'.")
|
||||
}
|
||||
}
|
||||
|
||||
def defaultDeployHost = script.commonPipelineEnvironment.getConfigProperty('DEPLOY_HOST')
|
||||
def defaultDeployAccount = script.commonPipelineEnvironment.getConfigProperty('CI_DEPLOY_ACCOUNT')
|
||||
def defaultCredentialsId = script.commonPipelineEnvironment.getConfigProperty('neoCredentialsId')
|
||||
if (defaultCredentialsId == null) {
|
||||
defaultCredentialsId = 'CI_CREDENTIALS_ID'
|
||||
if (deployMode.equals('mta') || deployMode.equals('warParams')) {
|
||||
deployHost = utils.getMandatoryParameter(configuration, 'host')
|
||||
deployAccount = utils.getMandatoryParameter(configuration, 'account')
|
||||
}
|
||||
|
||||
def deployHost
|
||||
def deployAccount
|
||||
|
||||
if (deployMode.equals('mta') || deployMode.equals('warParams')) {
|
||||
deployHost = utils.getMandatoryParameter(parameters, 'deployHost', defaultDeployHost)
|
||||
deployAccount = utils.getMandatoryParameter(parameters, 'deployAccount', defaultDeployAccount)
|
||||
}
|
||||
|
||||
def credentialsId = parameters.get('neoCredentialsId', defaultCredentialsId)
|
||||
|
||||
def neoExecutable = getNeoExecutable(parameters)
|
||||
def neoExecutable = getNeoExecutable(configuration)
|
||||
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: credentialsId,
|
||||
@ -113,13 +178,13 @@ def call(parameters = [:]) {
|
||||
}
|
||||
}
|
||||
|
||||
private getNeoExecutable(parameters) {
|
||||
private getNeoExecutable(configuration) {
|
||||
|
||||
def neoExecutable = 'neo' // default, if nothing below applies maybe it is the path.
|
||||
|
||||
if (parameters?.neoHome) {
|
||||
neoExecutable = "${parameters.neoHome}/tools/neo.sh"
|
||||
echo "[neoDeploy] Neo executable \"${neoExecutable}\" retrieved from parameters."
|
||||
if (configuration.neoHome) {
|
||||
neoExecutable = "${configuration.neoHome}/tools/neo.sh"
|
||||
echo "[neoDeploy] Neo executable \"${neoExecutable}\" retrieved from configuration."
|
||||
return neoExecutable
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user