2017-07-11 15:12:03 +02:00
import com.sap.piper.Utils
2017-12-11 11:15:51 +01:00
import com.sap.piper.ConfigurationLoader
import com.sap.piper.ConfigurationMerger
import com.sap.piper.ConfigurationType
2017-11-24 15:59:34 +01:00
2017-07-11 15:12:03 +02:00
def call ( parameters = [ : ] ) {
2017-12-11 11:15:51 +01:00
def stepName = 'neoDeploy'
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 ]
2017-07-11 15:12:03 +02:00
def utils = new Utils ( )
2017-12-11 13:55:07 +01:00
2017-12-11 11:15:51 +01:00
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 . 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 )
}
2017-07-11 15:12:03 +02:00
2017-12-11 11:15:51 +01:00
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 )
2017-07-11 15:12:03 +02:00
}
2017-12-11 11:15:51 +01:00
// 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
2017-12-28 13:10:11 +01:00
2018-01-17 11:17:24 +01:00
if ( deployMode ! = 'mta' & & deployMode ! = 'warParams' & & deployMode ! = 'warPropertiesFile' ) {
2018-01-17 11:19:02 +01:00
throw new Exception ( "[neoDeploy] Invalid deployMode = '${deployMode}'. Valid 'deployMode' values are: 'mta', 'warParams' and 'warPropertiesFile'" )
2018-01-16 10:54:17 +01:00
}
2018-01-17 11:17:24 +01:00
if ( deployMode = = 'warPropertiesFile' | | deployMode = = 'warParams' ) {
2017-12-11 11:15:51 +01:00
warAction = utils . getMandatoryParameter ( configuration , 'warAction' )
2018-01-17 13:48:26 +01:00
if ( warAction ! = 'deploy' & & warAction ! = 'rolling-update' ) {
2018-01-17 11:19:02 +01:00
throw new Exception ( "[neoDeploy] Invalid warAction = '${warAction}'. Valid 'warAction' values are: 'deploy' and 'rolling-update'." )
2018-01-16 10:54:17 +01:00
}
}
2017-12-11 11:15:51 +01:00
2018-01-17 11:17:24 +01:00
if ( deployMode = = 'warPropertiesFile' ) {
2017-12-11 11:15:51 +01:00
propertiesFile = utils . getMandatoryParameter ( configuration , 'propertiesFile' )
2018-01-12 13:02:48 +01:00
if ( ! fileExists ( propertiesFile ) ) {
2018-01-11 15:25:58 +01:00
error "Properties file cannot be found with parameter propertiesFile: '${propertiesFile}'."
}
2017-12-28 13:10:11 +01:00
}
2018-01-17 11:17:24 +01:00
if ( deployMode = = 'warParams' ) {
2017-12-11 11:15:51 +01:00
applicationName = utils . getMandatoryParameter ( configuration , 'applicationName' )
runtime = utils . getMandatoryParameter ( configuration , 'runtime' )
runtimeVersion = utils . getMandatoryParameter ( configuration , 'runtimeVersion' )
vmSize = configuration . vmSize
2018-01-16 10:54:17 +01:00
if ( vmSize ! = 'lite' & & vmSize ! = 'pro' & & vmSize ! = 'prem' & & vmSize ! = 'prem-plus' ) {
2018-01-17 11:19:02 +01:00
throw new Exception ( "[neoDeploy] Invalid vmSize = '${vmSize}'. Valid 'vmSize' values are: 'lite', 'pro', 'prem' and 'prem-plus'." )
2018-01-11 15:25:58 +01:00
}
2017-12-28 13:10:11 +01:00
}
2017-12-11 11:15:51 +01:00
if ( deployMode . equals ( 'mta' ) | | deployMode . equals ( 'warParams' ) ) {
deployHost = utils . getMandatoryParameter ( configuration , 'host' )
deployAccount = utils . getMandatoryParameter ( configuration , 'account' )
2017-12-28 13:10:11 +01:00
}
2017-12-11 11:15:51 +01:00
def neoExecutable = getNeoExecutable ( configuration )
2017-07-11 15:12:03 +02:00
2017-12-13 10:05:19 +01:00
def neoDeployScript
if ( deployMode = = 'mta' ) {
neoDeployScript =
"" " # ! /bin/ bash
"${neoExecutable}" deploy - mta \
- - host '${deployHost}' \
- - account '${deployAccount}' \
- - synchronous "" "
}
if ( deployMode = = 'warParams' ) {
neoDeployScript =
"" " # ! /bin/ bash
"${neoExecutable}" $ { warAction } \
- - host '${deployHost}' \
- - account '${deployAccount}' \
- - application '${applicationName}' \
- - runtime '${runtime}' \
- - runtime - version '${runtimeVersion}' \
- - size '${vmSize}' "" "
}
if ( deployMode = = 'warPropertiesFile' ) {
neoDeployScript =
"" " # ! /bin/ bash
"${neoExecutable}" $ { warAction } \
$ { propertiesFile } "" "
}
2018-01-10 13:22:36 +01:00
withCredentials ( [ usernamePassword (
credentialsId: credentialsId ,
passwordVariable: 'password' ,
usernameVariable: 'username' ) ] ) {
def commonDeployParams =
"" " - - user '${username}' \
- - password '${password}' \
2018-01-12 13:02:48 +01:00
- - source "${archivePath}" \
2018-01-10 13:22:36 +01:00
"" "
2017-12-13 10:05:19 +01:00
dockerExecute ( dockerImage: configuration . get ( 'dockerImage' ) ,
dockerEnvVars: configuration . get ( 'dockerEnvVars' ) ,
dockerOptions: configuration . get ( 'dockerOptions' ) ) {
2018-01-10 13:22:36 +01:00
2017-12-13 10:05:19 +01:00
sh "" " $ { neoDeployScript } \
$ { commonDeployParams }
2017-12-28 13:10:11 +01:00
"" "
}
2017-07-11 15:12:03 +02:00
}
}
}
2017-12-11 11:15:51 +01:00
private getNeoExecutable ( configuration ) {
2017-07-11 15:12:03 +02:00
2017-12-15 15:34:25 +01:00
def neoExecutable = 'neo.sh' // default, if nothing below applies maybe it is the path.
2017-07-11 15:12:03 +02:00
2017-12-11 11:15:51 +01:00
if ( configuration . neoHome ) {
neoExecutable = "${configuration.neoHome}/tools/neo.sh"
echo "[neoDeploy] Neo executable \"${neoExecutable}\" retrieved from configuration."
2017-07-11 15:12:03 +02:00
return neoExecutable
}
if ( env ? . NEO_HOME ) {
neoExecutable = "${env.NEO_HOME}/tools/neo.sh"
echo "[neoDeploy] Neo executable \"${neoExecutable}\" retrieved from environment."
return neoExecutable
}
echo "Using Neo executable from PATH."
return neoExecutable
}