1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/vars/neoDeploy.groovy

207 lines
8.0 KiB
Groovy
Raw Normal View History

2017-07-11 15:12:03 +02:00
import com.sap.piper.Utils
2018-02-20 16:30:34 +02:00
import com.sap.piper.ConfigurationLoader
import com.sap.piper.ConfigurationMerger
import com.sap.piper.ConfigurationType
2018-03-19 19:29:41 +02:00
import com.sap.piper.tools.ToolDescriptor
2018-02-20 16:30:34 +02:00
2017-07-11 15:12:03 +02:00
def call(parameters = [:]) {
def stepName = 'neoDeploy'
Set parameterKeys = [
'applicationName',
'archivePath',
'account',
'deployAccount', //deprecated, replaced by parameter 'account'
'deployHost', //deprecated, replaced by parameter 'host'
'deployMode',
'dockerEnvVars',
'dockerImage',
'dockerOptions',
'host',
'neoCredentialsId',
'neoHome',
'propertiesFile',
'runtime',
'runtimeVersion',
'vmSize',
'warAction'
]
Set stepConfigurationKeys = [
'account',
'dockerEnvVars',
'dockerImage',
'dockerOptions',
'host',
'neoCredentialsId',
'neoHome'
]
handlePipelineStepErrors (stepName: stepName, stepParameters: parameters) {
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
2017-07-11 15:12:03 +02:00
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 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.deployHost && !parameters.host) {
echo "[WARNING][${stepName}] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead."
parameters.put('host', parameters.deployHost)
}
2017-07-11 15:12:03 +02:00
if(parameters.deployAccount && !parameters.account) {
echo "[WARNING][${stepName}] Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead."
parameters.put('account', parameters.deployAccount)
2017-07-11 15:12:03 +02:00
}
def credId = script.commonPipelineEnvironment.getConfigProperty('neoCredentialsId')
if(credId && !parameters.neoCredentialsId) {
echo "[WARNING][${stepName}] Deprecated parameter 'neoCredentialsId' from old configuration framework is used. This will not work anymore in future versions."
parameters.put('neoCredentialsId', credId)
}
// 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
def deployModes = ['mta', 'warParams', 'warPropertiesFile']
if (! (deployMode in deployModes)) {
throw new Exception("[neoDeploy] Invalid deployMode = '${deployMode}'. Valid 'deployMode' values are: ${deployModes}.")
}
if (deployMode in ['warPropertiesFile', 'warParams']) {
warAction = utils.getMandatoryParameter(configuration, 'warAction')
def warActions = ['deploy', 'rolling-update']
if (! (warAction in warActions)) {
throw new Exception("[neoDeploy] Invalid warAction = '${warAction}'. Valid 'warAction' values are: ${warActions}.")
}
} else if(deployMode == 'mta') {
warAction = 'deploy-mta'
}
if (deployMode == 'warPropertiesFile') {
propertiesFile = utils.getMandatoryParameter(configuration, 'propertiesFile')
if (!fileExists(propertiesFile)){
error "Properties file cannot be found with parameter propertiesFile: '${propertiesFile}'."
}
}
if (deployMode == 'warParams') {
applicationName = utils.getMandatoryParameter(configuration, 'applicationName')
runtime = utils.getMandatoryParameter(configuration, 'runtime')
runtimeVersion = utils.getMandatoryParameter(configuration, 'runtimeVersion')
def vmSizes = ['lite', 'pro', 'prem', 'prem-plus']
vmSize = configuration.vmSize
if (! (vmSize in vmSizes)) {
throw new Exception("[neoDeploy] Invalid vmSize = '${vmSize}'. Valid 'vmSize' values are: ${vmSizes}.")
}
}
if (deployMode in ['mta','warParams']) {
deployHost = utils.getMandatoryParameter(configuration, 'host')
deployAccount = utils.getMandatoryParameter(configuration, 'account')
}
def neo = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', null, 'version')
2018-04-10 18:23:44 +02:00
def neoExecutable = neo.getToolExecutable(this, configuration)
def neoDeployScript = """#!/bin/bash
"${neoExecutable}" ${warAction} \
--source "${archivePath}" \
"""
2017-12-13 11:05:19 +02:00
2018-04-20 15:20:50 +02:00
if (deployMode in ['mta', 'warParams']) {
neoDeployScript +=
"""--host '${deployHost}' \
2017-12-13 11:05:19 +02:00
--account '${deployAccount}' \
2018-04-20 15:20:50 +02:00
"""
}
if (deployMode == 'mta') {
neoDeployScript += "--synchronous"
2017-12-13 11:05:19 +02:00
}
if (deployMode == 'warParams') {
neoDeployScript +=
2018-04-20 15:20:50 +02:00
"""--application '${applicationName}' \
2017-12-13 11:05:19 +02:00
--runtime '${runtime}' \
--runtime-version '${runtimeVersion}' \
--size '${vmSize}'"""
}
if (deployMode == 'warPropertiesFile') {
neoDeployScript +=
"""${propertiesFile}"""
2017-12-13 11:05:19 +02:00
}
withCredentials([usernamePassword(
credentialsId: credentialsId,
passwordVariable: 'password',
usernameVariable: 'username')]) {
2018-04-20 15:44:39 +02:00
def credentials =
"""--user '${username}' \
--password '${password}' \
"""
2017-12-13 11:05:19 +02:00
dockerExecute(dockerImage: configuration.get('dockerImage'),
dockerEnvVars: configuration.get('dockerEnvVars'),
dockerOptions: configuration.get('dockerOptions')) {
2018-03-19 19:29:41 +02:00
neo.verify(this, configuration)
2018-03-19 19:29:41 +02:00
def java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1')
java.verify(this, configuration)
2017-12-13 11:05:19 +02:00
sh """${neoDeployScript} \
2018-04-20 15:44:39 +02:00
${credentials}
"""
}
2017-07-11 15:12:03 +02:00
}
}
}