2021-01-26 10:29:44 +02:00
|
|
|
import com.cloudbees.groovy.cps.NonCPS
|
|
|
|
|
2019-04-01 13:54:01 +02:00
|
|
|
import com.sap.piper.GenerateDocumentation
|
2018-08-15 09:26:38 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2017-07-11 15:12:03 +02:00
|
|
|
import com.sap.piper.Utils
|
2019-04-02 09:33:40 +02:00
|
|
|
import com.sap.piper.StepAssertions
|
2019-01-28 12:32:24 +02:00
|
|
|
import com.sap.piper.tools.neo.DeployMode
|
|
|
|
import com.sap.piper.tools.neo.NeoCommandHelper
|
|
|
|
import com.sap.piper.tools.neo.WarAction
|
2018-08-15 09:26:38 +02:00
|
|
|
import groovy.transform.Field
|
|
|
|
|
2019-01-28 12:32:24 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
2018-11-29 10:54:05 +02:00
|
|
|
@Field String STEP_NAME = getClass().getName()
|
2019-04-01 13:54:01 +02:00
|
|
|
|
2019-01-28 12:32:24 +02:00
|
|
|
@Field Set GENERAL_CONFIG_KEYS = [
|
2019-04-01 13:54:01 +02:00
|
|
|
'neo',
|
|
|
|
/**
|
2022-11-29 10:52:23 +02:00
|
|
|
* The SAP BTP account to deploy to.
|
2019-04-01 13:54:01 +02:00
|
|
|
* @parentConfigKey neo
|
|
|
|
* @mandatory for deployMode=warParams
|
|
|
|
*/
|
|
|
|
'account',
|
|
|
|
/**
|
|
|
|
* Name of the application you want to manage, configure, or deploy.
|
|
|
|
* @parentConfigKey neo
|
|
|
|
* @mandatory for deployMode=warParams
|
|
|
|
*/
|
|
|
|
'application',
|
|
|
|
/**
|
2021-01-26 10:29:44 +02:00
|
|
|
* The Jenkins credentials containing either user and password (UsernamePassword type credential) or json containing clientId, client secret and oauth service url (SecretFile type credential) used for SAP CP deployment.
|
2019-04-01 13:54:01 +02:00
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
|
|
|
'credentialsId',
|
2021-01-26 10:29:44 +02:00
|
|
|
/**
|
|
|
|
* The Jenkins credential of type 'UsernamePassword' or 'SecretFile'.
|
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
|
|
|
'credentialType',
|
2019-04-01 13:54:01 +02:00
|
|
|
/**
|
|
|
|
* Map of environment variables in the form of KEY: VALUE.
|
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
|
|
|
'environment',
|
|
|
|
/**
|
2022-11-29 10:52:23 +02:00
|
|
|
* The SAP BTP host to deploy to.
|
2019-04-01 13:54:01 +02:00
|
|
|
* @parentConfigKey neo
|
|
|
|
* @mandatory for deployMode=warParams
|
|
|
|
*/
|
|
|
|
'host',
|
2020-11-09 13:15:00 +02:00
|
|
|
/**
|
2019-04-01 13:54:01 +02:00
|
|
|
* The path to the .properties file in which all necessary deployment properties for the application are defined.
|
|
|
|
* @parentConfigKey neo
|
|
|
|
* @mandatory for deployMode=warPropertiesFile
|
|
|
|
*/
|
|
|
|
'propertiesFile',
|
|
|
|
/**
|
2022-11-29 10:52:23 +02:00
|
|
|
* Name of SAP BTP application runtime.
|
2019-04-01 13:54:01 +02:00
|
|
|
* @parentConfigKey neo
|
|
|
|
* @mandatory for deployMode=warParams
|
|
|
|
*/
|
|
|
|
'runtime',
|
|
|
|
/**
|
2022-11-29 10:52:23 +02:00
|
|
|
* Version of SAP BTP application runtime.
|
2019-04-01 13:54:01 +02:00
|
|
|
* @parentConfigKey neo
|
|
|
|
* @mandatory for deployMode=warParams
|
|
|
|
*/
|
|
|
|
'runtimeVersion',
|
2020-11-09 13:15:00 +02:00
|
|
|
/**
|
2019-04-01 13:54:01 +02:00
|
|
|
* Compute unit (VM) size. Acceptable values: lite, pro, prem, prem-plus.
|
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
|
|
|
'size',
|
2020-11-09 13:15:00 +02:00
|
|
|
/**
|
2019-04-01 13:54:01 +02:00
|
|
|
* String of VM arguments passed to the JVM.
|
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
2020-11-09 13:15:00 +02:00
|
|
|
'vmArguments',
|
|
|
|
/**
|
|
|
|
* Boolean to enable/disable invalidating the cache after deployment.
|
|
|
|
* @possibleValues `true`, `false`
|
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
|
|
|
'invalidateCache',
|
|
|
|
/**
|
2022-11-29 10:52:23 +02:00
|
|
|
* Portal landscape region subscribed to in SAP BTP.
|
2020-11-09 13:15:00 +02:00
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
|
|
|
'portalLandscape',
|
|
|
|
/**
|
2022-11-29 10:52:23 +02:00
|
|
|
* UsernamePassword type credential containing SAP BTP OAuth client ID and client secret.
|
2020-11-09 13:15:00 +02:00
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
|
|
|
'oauthCredentialId',
|
|
|
|
/**
|
|
|
|
* Site ID of the SAP Fiori Launchpad containing the SAP Fiori app. If not set, the cache of the default site, as defined in the Portal service, is invalidated.
|
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
2022-04-14 07:33:43 +02:00
|
|
|
'siteId',
|
|
|
|
/**
|
|
|
|
* Availability zone of BTP NEO into which the application is deployed.
|
|
|
|
* @possibleValues 1, 2
|
|
|
|
* @parentConfigKey neo
|
|
|
|
*/
|
|
|
|
'azDistribution'
|
2019-01-28 12:32:24 +02:00
|
|
|
]
|
2019-04-01 13:54:01 +02:00
|
|
|
|
2019-01-28 12:32:24 +02:00
|
|
|
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([
|
2020-06-24 10:56:36 +02:00
|
|
|
/**
|
|
|
|
* The deployment mode which should be used. Available options are:
|
|
|
|
* *`'mta'` - default,
|
|
|
|
* *`'warParams'` - deploying WAR file and passing all the deployment parameters via the function call,
|
|
|
|
* *`'warPropertiesFile'` - deploying WAR file and putting all the deployment parameters in a .properties file.
|
|
|
|
* @possibleValues 'mta', 'warParams', 'warPropertiesFile'
|
|
|
|
*/
|
|
|
|
'deployMode',
|
2019-04-01 13:54:01 +02:00
|
|
|
/**
|
|
|
|
* @see dockerExecute
|
|
|
|
*/
|
2018-08-15 09:26:38 +02:00
|
|
|
'dockerEnvVars',
|
2019-04-01 13:54:01 +02:00
|
|
|
/**
|
|
|
|
* @see dockerExecute
|
|
|
|
*/
|
2018-08-15 09:26:38 +02:00
|
|
|
'dockerImage',
|
2019-04-01 13:54:01 +02:00
|
|
|
/**
|
|
|
|
* @see dockerExecute
|
|
|
|
*/
|
2018-08-15 09:26:38 +02:00
|
|
|
'dockerOptions',
|
2019-05-10 16:41:40 +02:00
|
|
|
/**
|
2019-05-22 08:24:14 +02:00
|
|
|
* Extension files. Provided to the neo command via parameter `--extensions` (`-e`). Only valid for deploy mode `mta`.
|
2019-05-10 16:41:40 +02:00
|
|
|
*/
|
2019-05-23 09:20:10 +02:00
|
|
|
'extensions',
|
2019-04-01 13:54:01 +02:00
|
|
|
/**
|
2020-07-03 09:56:14 +02:00
|
|
|
* The path to the archive for deployment to SAP CP. If not provided the following defaults are used based on the deployMode:
|
|
|
|
* *`'mta'` - The `mtarFilePath` from common pipeline environment is used instead.
|
|
|
|
* *`'warParams'` and `'warPropertiesFile'` - The following template will be used "<mavenDeploymentModule>/target/<artifactId>.<packaging>"
|
2019-04-01 13:54:01 +02:00
|
|
|
*/
|
2020-07-03 09:56:14 +02:00
|
|
|
'source',
|
|
|
|
/**
|
|
|
|
* Path to the maven module which contains the deployment artifact.
|
|
|
|
*/
|
|
|
|
'mavenDeploymentModule'
|
2019-01-28 12:32:24 +02:00
|
|
|
])
|
|
|
|
|
2018-08-15 09:26:38 +02:00
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS.plus([
|
2019-04-01 13:54:01 +02:00
|
|
|
/**
|
|
|
|
* Action mode when using WAR file mode. Available options are `deploy` (default) and `rolling-update` which performs update of an application without downtime in one go.
|
|
|
|
* @possibleValues 'deploy', 'rolling-update'
|
|
|
|
*/
|
2018-08-15 09:26:38 +02:00
|
|
|
'warAction'
|
|
|
|
])
|
2018-02-20 16:30:34 +02:00
|
|
|
|
2019-04-01 13:54:01 +02:00
|
|
|
/**
|
2022-11-29 10:52:23 +02:00
|
|
|
* Deploys an Application to SAP BTP (SAP CP) using the SAP BTP Console Client (Neo Java Web SDK).
|
2019-04-01 13:54:01 +02:00
|
|
|
*/
|
|
|
|
@GenerateDocumentation
|
2018-08-30 16:33:07 +02:00
|
|
|
void call(parameters = [:]) {
|
2019-01-28 12:32:24 +02:00
|
|
|
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
2017-12-11 12:15:51 +02:00
|
|
|
|
2018-10-31 09:40:12 +02:00
|
|
|
def script = checkScript(this, parameters) ?: this
|
2018-11-08 10:44:11 +02:00
|
|
|
def utils = parameters.utils ?: new Utils()
|
2020-08-26 15:32:58 +02:00
|
|
|
String stageName = parameters.stageName ?: env.STAGE_NAME
|
2017-12-11 14:55:07 +02:00
|
|
|
|
2018-08-15 09:26:38 +02:00
|
|
|
// load default & individual configuration
|
2019-03-13 16:32:31 +02:00
|
|
|
ConfigurationHelper configHelper = ConfigurationHelper.newInstance(this)
|
2020-08-26 15:32:58 +02:00
|
|
|
.loadStepDefaults([:], stageName)
|
2018-08-15 09:26:38 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
2019-01-28 13:35:35 +02:00
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
2020-08-26 15:32:58 +02:00
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, stageName, STEP_CONFIG_KEYS)
|
2019-01-28 13:35:35 +02:00
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
2019-03-20 13:14:57 +02:00
|
|
|
.collectValidationFailures()
|
2019-01-28 12:32:24 +02:00
|
|
|
.withPropertyInValues('deployMode', DeployMode.stringValues())
|
2019-03-13 16:32:31 +02:00
|
|
|
|
|
|
|
Map configuration = configHelper.use()
|
|
|
|
|
|
|
|
DeployMode deployMode = DeployMode.fromString(configuration.deployMode)
|
|
|
|
|
2019-03-20 13:14:57 +02:00
|
|
|
def isWarParamsDeployMode = { deployMode == DeployMode.WAR_PARAMS },
|
|
|
|
isNotWarPropertiesDeployMode = {deployMode != DeployMode.WAR_PROPERTIES_FILE}
|
2019-03-13 16:32:31 +02:00
|
|
|
|
2020-07-03 09:56:14 +02:00
|
|
|
if(!configuration.source){
|
|
|
|
configHelper.mixin([source: getDefaultSource(script, configuration, deployMode)])
|
|
|
|
}
|
|
|
|
|
|
|
|
configuration = configHelper
|
2019-03-20 13:14:57 +02:00
|
|
|
.withMandatoryProperty('source')
|
|
|
|
.withMandatoryProperty('neo/credentialsId')
|
2021-01-26 10:29:44 +02:00
|
|
|
.withMandatoryProperty('neo/credentialType')
|
2019-03-13 16:32:31 +02:00
|
|
|
.withMandatoryProperty('neo/application', null, isWarParamsDeployMode)
|
|
|
|
.withMandatoryProperty('neo/runtime', null, isWarParamsDeployMode)
|
|
|
|
.withMandatoryProperty('neo/runtimeVersion', null, isWarParamsDeployMode)
|
2019-03-20 13:14:57 +02:00
|
|
|
.withMandatoryProperty('neo/host', null, isNotWarPropertiesDeployMode)
|
|
|
|
.withMandatoryProperty('neo/account', null, isNotWarPropertiesDeployMode)
|
|
|
|
.use()
|
2018-08-30 16:33:07 +02:00
|
|
|
|
2019-05-23 10:19:49 +02:00
|
|
|
Set extensionFileNames
|
2019-05-10 16:41:40 +02:00
|
|
|
|
2019-05-23 09:20:10 +02:00
|
|
|
if(configuration.extensions == null) {
|
2019-05-23 10:19:49 +02:00
|
|
|
extensionFileNames = []
|
2019-05-10 16:41:40 +02:00
|
|
|
} else {
|
2019-05-23 10:19:49 +02:00
|
|
|
extensionFileNames = configuration.extensions in Collection ? configuration.extensions : [configuration.extensions]
|
2019-05-10 16:41:40 +02:00
|
|
|
}
|
|
|
|
|
2019-05-24 12:32:13 +02:00
|
|
|
if( ! extensionFileNames.findAll { it == null || it.isEmpty() }.isEmpty() )
|
|
|
|
error "At least one extension file name was null or empty: ${extensionFileNames}."
|
|
|
|
|
2019-05-23 10:19:49 +02:00
|
|
|
if(deployMode != DeployMode.MTA && ! extensionFileNames.isEmpty())
|
|
|
|
error "Extensions (${extensionFileNames} found for deploy mode ${deployMode}. Extensions are only supported for deploy mode '${DeployMode.MTA}')"
|
2019-05-10 16:41:40 +02:00
|
|
|
|
2018-08-30 11:03:34 +02:00
|
|
|
utils.pushToSWA([
|
2018-08-30 16:33:07 +02:00
|
|
|
step: STEP_NAME,
|
2019-01-21 09:47:34 +02:00
|
|
|
stepParamKey1: 'deployMode',
|
2018-08-30 11:03:34 +02:00
|
|
|
stepParam1: configuration.deployMode == 'mta'?'mta':'war', // ['mta', 'warParams', 'warPropertiesFile']
|
2019-01-21 09:47:34 +02:00
|
|
|
stepParamKey2: 'warAction',
|
2018-10-30 17:22:42 +02:00
|
|
|
stepParam2: configuration.warAction == 'rolling-update'?'blue-green':'standard', // ['deploy', 'deploy-mta', 'rolling-update']
|
2019-01-21 09:47:34 +02:00
|
|
|
stepParamKey3: 'scriptMissing',
|
2018-11-08 10:44:11 +02:00
|
|
|
stepParam3: parameters?.script == null,
|
2018-08-30 11:03:34 +02:00
|
|
|
], configuration)
|
2017-12-11 12:15:51 +02:00
|
|
|
|
2021-01-26 10:29:44 +02:00
|
|
|
if(configuration.neo.credentialType == 'UsernamePassword'){
|
|
|
|
withCredentials([usernamePassword(
|
|
|
|
credentialsId: configuration.neo.credentialsId,
|
|
|
|
passwordVariable: 'NEO_PASSWORD',
|
|
|
|
usernameVariable: 'NEO_USERNAME')]) {
|
|
|
|
|
|
|
|
assertPasswordRules(NEO_PASSWORD)
|
2019-01-28 12:32:24 +02:00
|
|
|
|
2021-01-26 10:29:44 +02:00
|
|
|
dockerExecute(
|
|
|
|
script: script,
|
|
|
|
dockerImage: configuration.dockerImage,
|
|
|
|
dockerEnvVars: configuration.dockerEnvVars,
|
|
|
|
dockerOptions: configuration.dockerOptions
|
|
|
|
) {
|
2019-01-29 10:48:52 +02:00
|
|
|
|
2021-01-26 10:29:44 +02:00
|
|
|
StepAssertions.assertFileExists(this, configuration.source)
|
|
|
|
|
|
|
|
for(CharSequence extensionFile in extensionFileNames) {
|
|
|
|
StepAssertions.assertFileExists(this, extensionFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
NeoCommandHelper neoCommandHelper = new NeoCommandHelper(
|
|
|
|
this,
|
|
|
|
deployMode,
|
|
|
|
configuration.neo,
|
|
|
|
extensionFileNames,
|
|
|
|
NEO_USERNAME,
|
|
|
|
NEO_PASSWORD,
|
|
|
|
configuration.source
|
|
|
|
)
|
|
|
|
|
|
|
|
lock("$STEP_NAME:${neoCommandHelper.resourceLock()}") {
|
|
|
|
deploy(script, configuration, neoCommandHelper, configuration.dockerImage, deployMode)
|
|
|
|
}
|
|
|
|
if(configuration.neo.invalidateCache == true) {
|
|
|
|
if (configuration.deployMode == 'mta') {
|
|
|
|
echo "Triggering invalidation of cache for html5 applications"
|
|
|
|
invalidateCache(configuration)
|
|
|
|
} else {
|
|
|
|
echo "Invalidation of cache is ignored. It is performed only for html5 applications."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(configuration.neo.credentialType == 'SecretFile'){
|
2019-01-29 10:48:52 +02:00
|
|
|
|
|
|
|
dockerExecute(
|
|
|
|
script: script,
|
|
|
|
dockerImage: configuration.dockerImage,
|
|
|
|
dockerEnvVars: configuration.dockerEnvVars,
|
|
|
|
dockerOptions: configuration.dockerOptions
|
|
|
|
) {
|
2021-01-26 10:29:44 +02:00
|
|
|
withCredentials([file(credentialsId: configuration.neo.credentialsId, variable: 'oauth_deploy_cred')]) {
|
|
|
|
deployWithBearerToken(oauth_deploy_cred, configuration, script)
|
2020-11-09 13:15:00 +02:00
|
|
|
}
|
2017-12-11 12:15:51 +02:00
|
|
|
}
|
|
|
|
}
|
2021-01-26 10:29:44 +02:00
|
|
|
else {
|
|
|
|
error "Unsupported type of neo deploy credential."
|
|
|
|
}
|
2019-01-28 12:32:24 +02:00
|
|
|
}
|
|
|
|
}
|
2017-12-11 12:15:51 +02:00
|
|
|
|
2020-11-09 13:15:00 +02:00
|
|
|
private invalidateCache(configuration){
|
|
|
|
def account = configuration.neo.account
|
|
|
|
def host = configuration.neo.host
|
|
|
|
def portalLandscape = configuration.neo.portalLandscape
|
|
|
|
|
|
|
|
withCredentials([usernamePassword(
|
|
|
|
credentialsId: configuration.neo.oauthCredentialId,
|
|
|
|
passwordVariable: 'OAUTH_NEO_CLIENT_SECRET',
|
|
|
|
usernameVariable: 'OAUTH_NEO_CLIENT_ID')]) {
|
|
|
|
def bearerTokenResponse = sh(
|
|
|
|
script: """#!/bin/bash
|
|
|
|
curl -X POST -u "${OAUTH_NEO_CLIENT_ID}:${OAUTH_NEO_CLIENT_SECRET}" \
|
|
|
|
--fail \
|
|
|
|
"https://oauthasservices-${account}.${host}/oauth2/api/v1/token?grant_type=client_credentials&scope=write,read"
|
|
|
|
""",
|
|
|
|
returnStdout: true)
|
|
|
|
def bearerToken = readJSON(text: bearerTokenResponse).access_token
|
|
|
|
|
|
|
|
echo "Retrieved bearer token."
|
|
|
|
|
|
|
|
def fetchXcsrfTokenResponse = sh(
|
|
|
|
script: """#!/bin/bash
|
|
|
|
curl -i -L \
|
|
|
|
-c 'cookies.jar' \
|
|
|
|
-H 'X-CSRF-Token: Fetch' \
|
|
|
|
-H "Authorization: Bearer ${bearerToken}" \
|
|
|
|
--fail \
|
|
|
|
"https://${portalLandscape}-${account}.${host}/fiori/api/v1/csrf"
|
|
|
|
""",
|
|
|
|
returnStdout: true)
|
|
|
|
|
|
|
|
def xcsrfToken = readProperties(text: fetchXcsrfTokenResponse)["X-CSRF-Token"]
|
|
|
|
def siteId = configuration.neo.siteId ?: ""
|
|
|
|
|
|
|
|
if(! siteId){
|
|
|
|
echo "Using the default site defined in Portal service and invalidating the cache."
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
echo "Invalidating the cache for site with Id: ${siteId}."
|
|
|
|
}
|
|
|
|
def statusCode = sh(
|
|
|
|
script: """#!/bin/bash
|
|
|
|
curl -X POST -L \
|
|
|
|
-b 'cookies.jar' \
|
|
|
|
-H "X-CSRF-Token: ${xcsrfToken}" \
|
|
|
|
-H "Authorization: Bearer ${bearerToken}" \
|
|
|
|
-d "{\"siteId\":${siteId}}" \
|
|
|
|
-so /dev/null \
|
|
|
|
-w '%{response_code}' \
|
|
|
|
"https://${portalLandscape}-${account}.${host}/fiori/v1/operations/invalidateCache"
|
|
|
|
""",
|
|
|
|
returnStdout: true).trim()
|
|
|
|
|
|
|
|
if(! siteId && statusCode == "500") {
|
|
|
|
error "Invalidating the cache failed. " +
|
|
|
|
"As no siteId is set, the default site defined in the portal UI is used. " +
|
|
|
|
"Please verify a default site is defined in Portal service. " +
|
|
|
|
"Alternatively, configure the siteId parameter for this step to invalidate the cache of that specific site."
|
|
|
|
} else if(! statusCode == "200" || ! statusCode == "201" ){
|
|
|
|
error "Invalidating the cache failed with response code: ${statusCode}."
|
|
|
|
}
|
|
|
|
echo "Successfully invalidated the cache."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-21 13:10:54 +02:00
|
|
|
private deploy(script, Map configuration, NeoCommandHelper neoCommandHelper, dockerImage, DeployMode deployMode) {
|
2018-01-16 11:54:17 +02:00
|
|
|
|
2020-07-01 16:36:08 +02:00
|
|
|
String logFolder = "logs/neo/${UUID.randomUUID()}"
|
2019-03-29 17:23:36 +02:00
|
|
|
|
2019-01-28 12:32:24 +02:00
|
|
|
try {
|
2019-03-29 17:23:36 +02:00
|
|
|
sh "mkdir -p ${logFolder}"
|
|
|
|
withEnv(["neo_logging_location=${pwd()}/${logFolder}"]) {
|
2019-01-28 12:32:24 +02:00
|
|
|
if (deployMode.isWarDeployment()) {
|
|
|
|
ConfigurationHelper.newInstance(this, configuration).withPropertyInValues('warAction', WarAction.stringValues())
|
|
|
|
WarAction warAction = WarAction.fromString(configuration.warAction)
|
2017-12-11 12:15:51 +02:00
|
|
|
|
2019-01-28 12:32:24 +02:00
|
|
|
if (warAction == WarAction.ROLLING_UPDATE) {
|
|
|
|
if (!isAppRunning(neoCommandHelper)) {
|
|
|
|
warAction = WarAction.DEPLOY
|
|
|
|
echo "Rolling update not possible because application is not running. Falling back to standard deployment."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "Link to the application dashboard: ${neoCommandHelper.cloudCockpitLink()}"
|
2017-12-28 14:10:11 +02:00
|
|
|
|
2019-01-28 12:32:24 +02:00
|
|
|
if (warAction == WarAction.ROLLING_UPDATE) {
|
2020-02-14 14:41:36 +02:00
|
|
|
try {
|
|
|
|
sh neoCommandHelper.rollingUpdateCommand()
|
|
|
|
} catch (e) {
|
2019-04-12 09:07:53 +02:00
|
|
|
error "[ERROR][${STEP_NAME}] The execution of the deploy command failed, see the log for details."
|
|
|
|
}
|
2019-01-28 12:32:24 +02:00
|
|
|
} else {
|
2020-02-14 14:41:36 +02:00
|
|
|
try {
|
|
|
|
sh neoCommandHelper.deployCommand()
|
|
|
|
} catch (e) {
|
2019-04-12 09:07:53 +02:00
|
|
|
error "[ERROR][${STEP_NAME}] The execution of the deploy command failed, see the log for details."
|
|
|
|
}
|
2019-01-28 12:32:24 +02:00
|
|
|
sh neoCommandHelper.restartCommand()
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} else if (deployMode == DeployMode.MTA) {
|
2020-02-14 14:41:36 +02:00
|
|
|
try {
|
|
|
|
sh neoCommandHelper.deployMta()
|
|
|
|
} catch (e) {
|
2019-04-12 09:07:53 +02:00
|
|
|
error "[ERROR][${STEP_NAME}] The execution of the deploy command failed, see the log for details."
|
|
|
|
}
|
2018-01-11 16:25:58 +02:00
|
|
|
}
|
2017-12-28 14:10:11 +02:00
|
|
|
}
|
2019-01-28 12:32:24 +02:00
|
|
|
}
|
|
|
|
catch (Exception ex) {
|
2019-03-29 16:02:09 +02:00
|
|
|
|
2022-11-29 10:52:23 +02:00
|
|
|
echo "Error while deploying to SAP BTP. Here are the neo.sh logs:"
|
2019-05-09 15:48:13 +02:00
|
|
|
try {
|
2019-03-29 17:23:36 +02:00
|
|
|
sh "cat ${logFolder}/*"
|
2019-05-09 15:48:13 +02:00
|
|
|
} catch(Exception e) {
|
|
|
|
echo "Unable to provide the logs."
|
|
|
|
ex.addSuppressed(e)
|
2017-12-28 14:10:11 +02:00
|
|
|
}
|
2019-01-28 12:32:24 +02:00
|
|
|
throw ex
|
|
|
|
}
|
|
|
|
}
|
2017-12-28 14:10:11 +02:00
|
|
|
|
2021-01-26 10:29:44 +02:00
|
|
|
private deployWithBearerToken(def credentialFilePath, Map configuration, Script script){
|
|
|
|
|
|
|
|
def deployArchive = script.commonPipelineEnvironment.getMtarFilePath()
|
|
|
|
def host = configuration.neo.host
|
|
|
|
def account = configuration.neo.account
|
|
|
|
|
|
|
|
def credentialFileContent = readFile(credentialFilePath)
|
|
|
|
def credentialsMap = parseJson(credentialFileContent)
|
|
|
|
|
|
|
|
def oauthClientId = credentialsMap.oauthClientId
|
|
|
|
def oauthClientSecret = credentialsMap.oauthClientSecret
|
|
|
|
def oauthUrl = credentialsMap.oauthServiceUrl
|
|
|
|
|
|
|
|
echo "[${STEP_NAME}] Retrieving oauth token..."
|
|
|
|
|
|
|
|
def myCurl = "curl --fail --silent --show-error --retry 12"
|
|
|
|
def token_json = sh(
|
|
|
|
script: """#!/bin/bash
|
|
|
|
${myCurl} -XPOST -u \"${oauthClientId}:${oauthClientSecret}\" \"${oauthUrl}/apitoken/v1?grant_type=client_credentials"
|
|
|
|
""",
|
|
|
|
returnStdout: true
|
|
|
|
)
|
|
|
|
def responseJson = readJSON text: token_json
|
|
|
|
def token = responseJson.access_token
|
|
|
|
|
|
|
|
echo "[${STEP_NAME}] Deploying '${deployArchive}' to '${account}'..."
|
|
|
|
|
|
|
|
def deploymentContentResponse = sh(
|
|
|
|
script: """#!/bin/bash
|
|
|
|
${myCurl} -XPOST -H \"Authorization: Bearer ${token}\" -F file=@\"${deployArchive}\" \"https://slservice.${host}/slservice/v1/oauth/accounts/${account}/mtars\"
|
|
|
|
""",
|
|
|
|
returnStdout: true
|
|
|
|
)
|
|
|
|
def deploymentJson = readJSON text: deploymentContentResponse
|
|
|
|
def deploymentId = deploymentJson.id
|
|
|
|
|
|
|
|
echo "[${STEP_NAME}] Deployment Id is '${deploymentId}'."
|
|
|
|
|
|
|
|
def statusPollScript = """#!/bin/bash
|
|
|
|
${myCurl} -XGET -H \"Authorization: Bearer ${token}\" \"https://slservice.${host}/slservice/v1/oauth/accounts/${account}/mtars/${deploymentId}\"
|
|
|
|
"""
|
|
|
|
def statusResponse = sh(script: statusPollScript, returnStdout: true)
|
|
|
|
def statusJson = readJSON text: statusResponse
|
|
|
|
def state = statusJson.state
|
|
|
|
|
|
|
|
while (state == 'RUNNING') {
|
|
|
|
sleep(10)
|
|
|
|
statusResponse = sh(script: statusPollScript, returnStdout: true)
|
|
|
|
statusJson = readJSON text: statusResponse
|
|
|
|
state = statusJson.state
|
|
|
|
echo "${STEP_NAME}] Deployment is still running..."
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == 'DONE') {
|
|
|
|
echo "[${STEP_NAME}] Deployment has succeeded."
|
|
|
|
} else if (state == 'FAILED') {
|
|
|
|
if(statusJson.progress[0]?.modules[0]?.error?.internalMessage) {
|
|
|
|
def message = statusJson.progress[0].modules[0].error.internalMessage
|
|
|
|
echo "[${STEP_NAME}] Deployment has failed with the message: ${message}"
|
|
|
|
error "[${STEP_NAME}] Deployment failure message: ${message}"
|
|
|
|
} else {
|
|
|
|
echo "[${STEP_NAME}] Deployment has failed with response: ${statusResponse}"
|
|
|
|
error "[${STEP_NAME}] Deployment failure reason: ${statusResponse}"
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
echo "[${STEP_NAME}] Unknown status '${state}'"
|
|
|
|
error "[${STEP_NAME}] Deployment failed with unknown status: ${state}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-28 12:32:24 +02:00
|
|
|
private boolean isAppRunning(NeoCommandHelper commandHelper) {
|
|
|
|
def status = sh script: "${commandHelper.statusCommand()} || true", returnStdout: true
|
|
|
|
return status.contains('Status: STARTED')
|
|
|
|
}
|
2018-04-20 15:20:50 +02:00
|
|
|
|
2019-01-28 12:32:24 +02:00
|
|
|
private assertPasswordRules(String password) {
|
|
|
|
if (password.startsWith("@")) {
|
2022-11-29 10:52:23 +02:00
|
|
|
error("Your password for the deployment to SAP BTP contains characters which are not " +
|
2019-01-28 12:32:24 +02:00
|
|
|
"supported by the neo tools. " +
|
|
|
|
"For example it is not allowed that the password starts with @. " +
|
|
|
|
"Please consult the documentation for the neo command line tool for more information: " +
|
|
|
|
"https://help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/8900b22376f84c609ee9baf5bf67130a.html")
|
2017-07-11 15:12:03 +02:00
|
|
|
}
|
|
|
|
}
|
2020-07-03 09:56:14 +02:00
|
|
|
|
|
|
|
private getDefaultSource(Script script, Map configuration, DeployMode deployMode){
|
|
|
|
if(deployMode == DeployMode.MTA) {
|
|
|
|
return script.commonPipelineEnvironment.getMtarFilePath()
|
|
|
|
}
|
|
|
|
|
|
|
|
String pomFile = "${configuration.mavenDeploymentModule}/pom.xml"
|
|
|
|
|
|
|
|
if(!fileExists(pomFile)){
|
|
|
|
error("The configured mavenDeploymentModule (${configuration.mavenDeploymentModule}) does not contain a pom file.")
|
|
|
|
}
|
|
|
|
|
|
|
|
def pom = readMavenPom file: pomFile
|
|
|
|
|
|
|
|
String source = "${configuration.mavenDeploymentModule}/target/${pom.artifactId}.${pom.packaging}"
|
|
|
|
|
|
|
|
return source
|
|
|
|
}
|
2021-01-26 10:29:44 +02:00
|
|
|
|
|
|
|
//Convert LazyMap instance produced after jsonSluper to a groovy based LinkedHashMap to overcome serialization issue
|
|
|
|
@NonCPS
|
|
|
|
def parseJson(credentialFileContent) {
|
|
|
|
def lazyMap = new groovy.json.JsonSlurper().parseText(credentialFileContent)
|
|
|
|
def map = [:]
|
|
|
|
for (prop in lazyMap) {
|
|
|
|
map[prop.key] = prop.value
|
|
|
|
}
|
|
|
|
return map
|
|
|
|
}
|