1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-03-03 15:02:35 +02:00
sap-jenkins-library/vars/neoDeploy.groovy

143 lines
5.7 KiB
Groovy
Raw Normal View History

2017-07-11 15:12:03 +02:00
import com.sap.piper.Utils
2017-07-11 15:12:03 +02:00
def call(parameters = [:]) {
handlePipelineStepErrors (stepName: 'neoDeploy', stepParameters: parameters) {
2017-07-11 15:12:03 +02:00
def utils = new Utils()
def script = parameters.script
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())
}
if (!archivePath.exists()){
2017-07-11 15:12:03 +02:00
error "Archive cannot be found with parameter archivePath: '${archivePath}'."
}
def deployMode = utils.getMandatoryParameter(parameters, 'deployMode', 'mta')
if (deployMode != 'mta' && deployMode != 'warParams' && deployMode != 'warPropertiesFile') {
throw new IllegalArgumentException("[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')
if (warAction != 'warAction' && warAction != 'deploy') {
throw new IllegalArgumentException("[neoDeploy] Invalid warAction = '${warAction}'. Valid 'warAction' values are: 'deploy' and 'rolling-update'.")
}
}
if (deployMode == 'warPropertiesFile') {
propertiesFile = new File(utils.getMandatoryParameter(parameters, 'propertiesFile', null))
if (!propertiesFile.isAbsolute()) {
propertiesFile = new File(pwd(), propertiesFile.getPath())
}
if (!propertiesFile.exists()){
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')
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'.")
}
}
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'
}
def deployHost
def deployAccount
if (deployMode.equals('mta') || deployMode.equals('warParams')) {
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)
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()}" \
"""
if (deployMode == 'mta') {
sh """#!/bin/bash
"${neoExecutable}" deploy-mta \
2018-01-10 15:25:50 +01:00
${commonDeployParams} \
--host '${deployHost}' \
--account '${deployAccount}' \
2017-07-11 15:12:03 +02:00
--synchronous
"""
}
if (deployMode == 'warParams') {
sh """#!/bin/bash
"${neoExecutable}" ${warAction} \
2018-01-10 15:25:50 +01:00
${commonDeployParams} \
--host '${deployHost}' \
--account '${deployAccount}' \
--application '${applicationName}' \
--runtime '${runtime}' \
--runtime-version '${runtimeVersion}' \
--size '${vmSize}'
"""
}
if (deployMode == 'warPropertiesFile') {
sh """#!/bin/bash
"${neoExecutable}" ${warAction} \
2018-01-10 15:25:50 +01:00
${commonDeployParams} \
${propertiesFile.getAbsolutePath()}
"""
}
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
}