2019-03-12 16:48:35 +02:00
|
|
|
import com.sap.piper.GenerateDocumentation
|
|
|
|
import com.sap.piper.CloudPlatform
|
|
|
|
import com.sap.piper.DeploymentType
|
|
|
|
import com.sap.piper.k8s.ContainerMap
|
|
|
|
import com.sap.piper.ConfigurationHelper
|
|
|
|
import com.sap.piper.Utils
|
|
|
|
import com.sap.piper.JenkinsUtils
|
|
|
|
|
|
|
|
import groovy.transform.Field
|
|
|
|
|
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
|
|
|
@Field String STEP_NAME = getClass().getName()
|
|
|
|
|
|
|
|
@Field Set GENERAL_CONFIG_KEYS = [
|
|
|
|
/** Defines the targets to deploy on cloudFoundry.*/
|
|
|
|
'cfTargets',
|
|
|
|
/** Defines the targets to deploy on neo.*/
|
|
|
|
'neoTargets'
|
|
|
|
]
|
|
|
|
|
|
|
|
@Field Set STEP_CONFIG_KEYS = []
|
|
|
|
|
|
|
|
@Field Set PARAMETER_KEYS = GENERAL_CONFIG_KEYS.plus([
|
|
|
|
/** Defines the deployment type.*/
|
|
|
|
'enableZeroDowntimeDeployment',
|
2020-06-24 10:56:36 +02:00
|
|
|
/** Executes the deployments in parallel.*/
|
|
|
|
'parallelExecution',
|
|
|
|
/** The source file to deploy to SAP Cloud Platform.*/
|
2019-03-12 16:48:35 +02:00
|
|
|
'source'
|
|
|
|
])
|
|
|
|
|
|
|
|
/**
|
2020-06-24 10:56:36 +02:00
|
|
|
* Deploys an application to multiple platforms (Cloud Foundry, SAP Cloud Platform) or to multiple instances of multiple platforms or the same platform.
|
2019-03-12 16:48:35 +02:00
|
|
|
*/
|
|
|
|
@GenerateDocumentation
|
|
|
|
void call(parameters = [:]) {
|
|
|
|
|
|
|
|
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
|
|
|
|
|
|
|
def script = checkScript(this, parameters) ?: this
|
|
|
|
def utils = parameters.utils ?: new Utils()
|
|
|
|
def jenkinsUtils = parameters.jenkinsUtils ?: new JenkinsUtils()
|
|
|
|
|
|
|
|
ConfigurationHelper configHelper = ConfigurationHelper.newInstance(this)
|
|
|
|
.loadStepDefaults()
|
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
|
|
|
|
Map config = configHelper.use()
|
|
|
|
|
|
|
|
configHelper
|
|
|
|
.withMandatoryProperty('source', null, { config.neoTargets })
|
|
|
|
|
|
|
|
utils.pushToSWA([
|
|
|
|
step: STEP_NAME,
|
2020-06-24 10:56:36 +02:00
|
|
|
stepParamKey1: 'enableZeroDowntimeDeployment',
|
|
|
|
stepParam1: config.enableZeroDowntimeDeployment
|
2019-03-12 16:48:35 +02:00
|
|
|
], config)
|
|
|
|
|
|
|
|
def index = 1
|
|
|
|
def deployments = [:]
|
|
|
|
|
|
|
|
if (config.cfTargets) {
|
|
|
|
|
2020-06-24 10:56:36 +02:00
|
|
|
def deploymentType = DeploymentType.selectFor(CloudPlatform.CLOUD_FOUNDRY, config.enableZeroDowntimeDeployment).toString()
|
|
|
|
def deployTool = script.commonPipelineEnvironment.configuration.isMta ? 'mtaDeployPlugin' : 'cf_native'
|
2019-03-12 16:48:35 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < config.cfTargets.size(); i++) {
|
|
|
|
|
|
|
|
def target = config.cfTargets[i]
|
|
|
|
|
|
|
|
Closure deployment = {
|
|
|
|
|
|
|
|
cloudFoundryDeploy(
|
|
|
|
script: script,
|
|
|
|
juStabUtils: utils,
|
|
|
|
jenkinsUtilsStub: jenkinsUtils,
|
|
|
|
deployType: deploymentType,
|
|
|
|
cloudFoundry: target,
|
|
|
|
mtaPath: script.commonPipelineEnvironment.mtarFilePath,
|
|
|
|
deployTool: deployTool
|
|
|
|
)
|
|
|
|
}
|
2020-06-24 10:56:36 +02:00
|
|
|
deployments.put("Deployment ${index}", deployment)
|
2019-03-12 16:48:35 +02:00
|
|
|
index++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.neoTargets) {
|
|
|
|
|
2020-06-24 10:56:36 +02:00
|
|
|
def deploymentType = DeploymentType.selectFor(CloudPlatform.NEO, config.enableZeroDowntimeDeployment).toString()
|
2019-03-12 16:48:35 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < config.neoTargets.size(); i++) {
|
|
|
|
|
|
|
|
def target = config.neoTargets[i]
|
|
|
|
|
|
|
|
Closure deployment = {
|
|
|
|
|
|
|
|
neoDeploy (
|
|
|
|
script: script,
|
2020-06-24 10:56:36 +02:00
|
|
|
warAction: deploymentType,
|
2019-03-12 16:48:35 +02:00
|
|
|
source: config.source,
|
|
|
|
neo: target
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
2020-06-24 10:56:36 +02:00
|
|
|
deployments.put("Deployment ${index}", deployment)
|
2019-03-12 16:48:35 +02:00
|
|
|
index++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!config.cfTargets && !config.neoTargets) {
|
|
|
|
error "Deployment skipped because no targets defined!"
|
|
|
|
}
|
|
|
|
|
2020-06-24 10:56:36 +02:00
|
|
|
echo "Executing deployments"
|
|
|
|
if (config.parallelExecution) {
|
|
|
|
echo "Executing deployments in parallel"
|
|
|
|
parallel deployments
|
2019-03-12 16:48:35 +02:00
|
|
|
} else {
|
2020-06-24 10:56:36 +02:00
|
|
|
echo "Executing deployments in sequence"
|
|
|
|
def closuresToRun = deployments.values().asList()
|
|
|
|
Collections.shuffle(closuresToRun) // Shuffle the list so no one tries to rely on the order of execution
|
|
|
|
for (int i = 0; i < closuresToRun.size(); i++) {
|
|
|
|
(closuresToRun[i] as Closure)()
|
2019-03-12 16:48:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|