2017-07-11 15:12:03 +02:00
|
|
|
import com.sap.piper.Utils
|
|
|
|
|
2017-11-24 15:59:34 +01:00
|
|
|
|
2017-07-11 15:12:03 +02:00
|
|
|
def call(parameters = [:]) {
|
|
|
|
|
2018-01-10 13:22:36 +01:00
|
|
|
handlePipelineStepErrors (stepName: 'neoDeploy', stepParameters: parameters) {
|
2017-07-11 15:12:03 +02:00
|
|
|
|
|
|
|
def utils = new Utils()
|
|
|
|
def script = parameters.script
|
2018-01-10 13:22:36 +01:00
|
|
|
if (script == null){
|
2017-07-11 15:12:03 +02:00
|
|
|
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
|
|
|
}
|
|
|
|
|
|
|
|
def archivePath = new File(utils.getMandatoryParameter(parameters, 'archivePath', null))
|
|
|
|
if (!archivePath.isAbsolute()) {
|
|
|
|
archivePath = new File(pwd(), archivePath.getPath())
|
|
|
|
}
|
2018-01-10 13:22:36 +01:00
|
|
|
if (!archivePath.exists()){
|
2017-07-11 15:12:03 +02:00
|
|
|
error "Archive cannot be found with parameter archivePath: '${archivePath}'."
|
|
|
|
}
|
|
|
|
|
2018-01-17 11:17:24 +01:00
|
|
|
def deployMode = utils.getMandatoryParameter(parameters, 'deployMode', 'mta')
|
2017-12-28 13:10:11 +01:00
|
|
|
|
2018-01-17 11:17:24 +01:00
|
|
|
if (deployMode != 'mta' && deployMode != 'warParams' && deployMode != 'warPropertiesFile') {
|
|
|
|
throw new IllegalArgumentException("[neoDeploy] Invalid deployMode = '${deployMode}'. Valid 'deployMode' values are: 'mta', 'warParams' and 'warPropertiesFile'")
|
2018-01-16 10:54:17 +01:00
|
|
|
}
|
|
|
|
|
2017-12-28 13:10:11 +01:00
|
|
|
def propertiesFile
|
|
|
|
def warAction
|
2018-01-17 11:17:24 +01:00
|
|
|
if (deployMode == 'warPropertiesFile' || deployMode == 'warParams') {
|
2018-01-16 10:54:17 +01:00
|
|
|
warAction = utils.getMandatoryParameter(parameters, 'warAction', 'deploy')
|
|
|
|
if (warAction != 'warAction' && warAction != 'deploy') {
|
|
|
|
throw new IllegalArgumentException("[neoDeploy] Invalid warAction = '${warAction}'. Valid 'warAction' values are: 'deploy' and 'rolling-update'.")
|
|
|
|
}
|
|
|
|
}
|
2018-01-17 11:17:24 +01:00
|
|
|
if (deployMode == 'warPropertiesFile') {
|
2017-12-28 13:10:11 +01:00
|
|
|
propertiesFile = new File(utils.getMandatoryParameter(parameters, 'propertiesFile', null))
|
|
|
|
if (!propertiesFile.isAbsolute()) {
|
|
|
|
propertiesFile = new File(pwd(), propertiesFile.getPath())
|
|
|
|
}
|
2018-01-11 15:25:58 +01:00
|
|
|
if (!propertiesFile.exists()){
|
|
|
|
error "Properties file cannot be found with parameter propertiesFile: '${propertiesFile}'."
|
|
|
|
}
|
2017-12-28 13:10:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
def applicationName
|
|
|
|
def runtime
|
|
|
|
def runtimeVersion
|
|
|
|
def vmSize
|
2018-01-17 11:17:24 +01:00
|
|
|
if (deployMode == 'warParams') {
|
2017-12-28 13:10:11 +01:00
|
|
|
applicationName = utils.getMandatoryParameter(parameters, 'applicationName', null)
|
|
|
|
runtime = utils.getMandatoryParameter(parameters, 'runtime', null)
|
|
|
|
runtimeVersion = utils.getMandatoryParameter(parameters, 'runtimeVersion', null)
|
|
|
|
vmSize = utils.getMandatoryParameter(parameters, 'vmSize', 'lite')
|
2018-01-16 10:54:17 +01:00
|
|
|
if (vmSize != 'lite' && vmSize !='pro' && vmSize != 'prem' && vmSize != 'prem-plus') {
|
|
|
|
throw new IllegalArgumentException("[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-07-11 15:12:03 +02:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
|
2017-12-28 13:10:11 +01:00
|
|
|
def deployHost
|
|
|
|
def deployAccount
|
2018-01-10 13:22:36 +01:00
|
|
|
|
2018-01-17 11:17:24 +01:00
|
|
|
if (deployMode.equals('mta') || deployMode.equals('warParams')) {
|
2017-12-28 13:10:11 +01:00
|
|
|
deployHost = utils.getMandatoryParameter(parameters, 'deployHost', defaultDeployHost)
|
|
|
|
deployAccount = utils.getMandatoryParameter(parameters, 'deployAccount', defaultDeployAccount)
|
|
|
|
}
|
|
|
|
|
2017-07-11 15:12:03 +02:00
|
|
|
def credentialsId = parameters.get('neoCredentialsId', defaultCredentialsId)
|
|
|
|
|
|
|
|
def neoExecutable = getNeoExecutable(parameters)
|
|
|
|
|
2018-01-10 13:22:36 +01:00
|
|
|
withCredentials([usernamePassword(
|
|
|
|
credentialsId: credentialsId,
|
|
|
|
passwordVariable: 'password',
|
|
|
|
usernameVariable: 'username')]) {
|
|
|
|
|
|
|
|
def commonDeployParams =
|
|
|
|
"""--user '${username}' \
|
|
|
|
--password '${password}' \
|
2018-01-10 15:25:50 +01:00
|
|
|
--source "${archivePath.getAbsolutePath()}" \
|
2018-01-10 13:22:36 +01:00
|
|
|
"""
|
|
|
|
|
2018-01-17 11:17:24 +01:00
|
|
|
if (deployMode == 'mta') {
|
2017-12-28 13:10:11 +01:00
|
|
|
sh """#!/bin/bash
|
|
|
|
"${neoExecutable}" deploy-mta \
|
2018-01-10 15:25:50 +01:00
|
|
|
${commonDeployParams} \
|
2017-12-01 09:24:27 +01:00
|
|
|
--host '${deployHost}' \
|
|
|
|
--account '${deployAccount}' \
|
2017-07-11 15:12:03 +02:00
|
|
|
--synchronous
|
2017-12-28 13:10:11 +01:00
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
2018-01-17 11:17:24 +01:00
|
|
|
if (deployMode == 'warParams') {
|
2017-12-28 13:10:11 +01:00
|
|
|
sh """#!/bin/bash
|
2018-01-11 15:25:58 +01:00
|
|
|
"${neoExecutable}" ${warAction} \
|
2018-01-10 15:25:50 +01:00
|
|
|
${commonDeployParams} \
|
2017-12-28 13:10:11 +01:00
|
|
|
--host '${deployHost}' \
|
2018-01-10 13:22:36 +01:00
|
|
|
--account '${deployAccount}' \
|
2017-12-28 13:10:11 +01:00
|
|
|
--application '${applicationName}' \
|
|
|
|
--runtime '${runtime}' \
|
|
|
|
--runtime-version '${runtimeVersion}' \
|
2018-01-10 13:22:36 +01:00
|
|
|
--size '${vmSize}'
|
2017-12-28 13:10:11 +01:00
|
|
|
"""
|
|
|
|
}
|
|
|
|
|
2018-01-17 11:17:24 +01:00
|
|
|
if (deployMode == 'warPropertiesFile') {
|
2017-12-28 13:10:11 +01:00
|
|
|
sh """#!/bin/bash
|
2018-01-11 15:25:58 +01:00
|
|
|
"${neoExecutable}" ${warAction} \
|
2018-01-10 15:25:50 +01:00
|
|
|
${commonDeployParams} \
|
2018-01-11 15:25:58 +01:00
|
|
|
${propertiesFile.getAbsolutePath()}
|
2017-12-28 13:10:11 +01:00
|
|
|
"""
|
|
|
|
}
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private getNeoExecutable(parameters) {
|
|
|
|
|
|
|
|
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."
|
|
|
|
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
|
|
|
|
}
|