Skip to content

Commit

Permalink
Merge 848a8fc into 2a09b9b
Browse files Browse the repository at this point in the history
  • Loading branch information
milkotodorov committed Dec 28, 2017
2 parents 2a09b9b + 848a8fc commit 8784450
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 22 deletions.
62 changes: 51 additions & 11 deletions documentation/docs/steps/neoDeploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,72 @@

## Description
Deploys an Application to SAP Cloud Platform (SAP CP) using the SAP Cloud Platform Console Client (Neo Java Web SDK).

## Prerequisites
* **SAP CP account** - the account to where the application is deployed.
* **SAP CP user for deployment** - a user with deployment permissions in the given account.
* **Jenkins credentials for deployment** - must be configured in Jenkins credentials with a dedicated Id.

![Jenkins credentials configuration](../images/neo_credentials.png)

* **Neo Java Web SDK** - can be downloaded from [Maven Central](http://central.maven.org/maven2/com/sap/cloud/neo-java-web-sdk/). The Neo Java Web SDK
needs to be extracted into the folder provided by `neoHome`. In case this parameters is not provided and there is no NEO_HOME parameter in the environment
`<neoRoot>/tools` needs to be in the `PATH`.

* **Java 8 or higher** - needed by the *Neo-Java-Web-SDK*

## Parameters
| parameter | mandatory | default | possible values |
| -------------------|-----------|----------------------------------------------------------------------------------------------|-----------------|
| `script` | yes | | |
| `archivePath` | yes | | |
| `deployHost` | no | `'DEPLOY_HOST'` from `commonPipelineEnvironment` | |
| `deployAccount` | no | `'CI_DEPLOY_ACCOUNT'` from `commonPipelineEnvironment` | |
| `neoCredentialsId` | no | `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | Environment is checked for `NEO_HOME`, <br>otherwise the neo toolset is expected in the path | |
## Parameters when using MTA deployment method (default - MTA)
| parameter | mandatory | default | possible values |
| -------------------|-----------|----------------------------------------------------------------------------------------------|-------------------------------------------------|
| `deployMode` | yes | `'MTA'` | `'MTA'`, `'WAR_PARAMS'`, `'WAR_PROPERTIESFILE'` |
| `script` | yes | | |
| `archivePath` | yes | | |
| `deployHost` | no | `'DEPLOY_HOST'` from `commonPipelineEnvironment` | |
| `deployAccount` | no | `'CI_DEPLOY_ACCOUNT'` from `commonPipelineEnvironment` | |
| `neoCredentialsId` | no | `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | Environment is checked for `NEO_HOME`, <br>otherwise the neo toolset is expected in the path | |

## Parameters when using WAR file deployment method with .properties file (WAR_PROPERTIESFILE)
| parameter | mandatory | default | possible values |
| -------------------|-----------|----------------------------------------------------------------------------------------------|-------------------------------------------------|
| `deployMode` | yes | `'MTA'` | `'MTA'`, `'WAR_PARAMS'`, `'WAR_PROPERTIESFILE'` |
| `warAction` | yes | `'deploy'` | `'deploy'`, `'rolling-update'` |
| `script` | yes | | |
| `archivePath` | yes | | |
| `neoCredentialsId` | no | `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | Environment is checked for `NEO_HOME`, <br>otherwise the neo toolset is expected in the path | |
| `propertiesFile` | yes | | |

## Parameters when using WAR file deployment method witout .properties file - with parameters (WAR_PARAMS)
| parameter | mandatory | default | possible values |
| -------------------|-----------|----------------------------------------------------------------------------------------------|-------------------------------------------------|
| `deployMode` | yes | `'MTA'` | `'MTA'`, `'WAR_PARAMS'`, `'WAR_PROPERTIESFILE'` |
| `warAction` | yes | `'deploy'` | `'deploy'`, `'rolling-update'` |
| `script` | yes | | |
| `archivePath` | yes | | |
| `deployHost` | no | `'DEPLOY_HOST'` from `commonPipelineEnvironment` | |
| `deployAccount` | no | `'CI_DEPLOY_ACCOUNT'` from `commonPipelineEnvironment` | |
| `neoCredentialsId` | no | `'CI_CREDENTIALS_ID'` | |
| `neoHome` | no | Environment is checked for `NEO_HOME`, <br>otherwise the neo toolset is expected in the path | |
| `applicationName` | yes | | |
| `runtime` | yes | | |
| `runtime-version` | yes | | |
| `size` | no | `'lite'` | `'lite'`, `'pro'`, `'prem'`, `'prem-plus'` |


* `deployMode` - The deployment mode which should be used. Available options are `'MTA'` (default), `'WAR_PARAMS'` (deploying WAR file and passing all the deployment parameters via the function call) and `'WAR_PROPERTIESFILE'` (deploying WAR file and putting all the deployment parameters in a .properties file)
* `script` - The common script environment of the Jenkinsfile run. Typically `this` is passed to this parameter. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for retrieving e.g. configuration parameters.
* `archivePath`- The path to the archive for deployment to SAP CP.
* `deployHost` - The SAP Cloud Platform host to deploy to.
* `deployAccount` - The SAP Cloud Platform account to deploy to.
* `credentialsId` - The Jenkins credentials containing user and password used for SAP CP deployment.
* `neoHome` - The path to the `neo-java-web-sdk` tool used for SAP CP deployment. If no parameter is provided, the path is retrieved from the Jenkins environment variables using `env.NEO_HOME`. If this Jenkins environment variable is not set it is assumed that the tool is available in the `PATH`.
* `propertiesFile` - The path to the .properties file in which all necessary deployment properties for the application are defined.
* `warAction` - 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.
* `applicationName` - Name of the application you want to manage, configure, or deploy
* `runtime` - Name of SAP Cloud Platform application runtime
* `runtime-version` - Version of SAP Cloud Platform application runtime
* `size` - Compute unit (VM) size. Acceptable values: lite, pro, prem, prem-plus.

## Return value
none
Expand All @@ -42,6 +78,10 @@ none
## Exceptions
* `Exception`:
* If `archivePath` is not provided.
* If `propertiesFile` is not provided (when using `'WAR_PROPERTIESFILE'` deployment mode).
* If `applicationName` is not provided (when using `'WAR_PARAMS'` deployment mode).
* If `runtime` is not provided (when using `'WAR_PARAMS'` deployment mode).
* If `runtime-version` is not provided (when using `'WAR_PARAMS'` deployment mode).
* `AbortException`:
* If neo-java-web-sdk is not installed, or `neoHome`is wrong.
* If `deployHost` is wrong.
Expand Down
87 changes: 76 additions & 11 deletions vars/neoDeploy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,114 @@ import com.sap.piper.Utils

def call(parameters = [:]) {

handlePipelineStepErrors (stepName: 'neoDeploy', stepParameters: parameters) {
handlePipelineStepErrors(stepName: 'neoDeploy', stepParameters: parameters) {

def utils = new Utils()
def script = parameters.script
if (script == null){
if (script == null) {
script = [commonPipelineEnvironment: commonPipelineEnvironment]
}

def archivePath = new File(utils.getMandatoryParameter(parameters, 'archivePath', null))
if (!archivePath.isAbsolute()) {
archivePath = new File(pwd(), archivePath.getPath())
}
if (!archivePath.exists()){
if (!archivePath.exists()) {
error "Archive cannot be found with parameter archivePath: '${archivePath}'."
}

def deployMode = utils.getMandatoryParameter(parameters, 'deployMode', 'MTA')

def propertiesFile
def warAction
if (deployMode == 'WAR_PROPERTIESFILE') {
propertiesFile = new File(utils.getMandatoryParameter(parameters, 'propertiesFile', null))
if (!propertiesFile.isAbsolute()) {
propertiesFile = new File(pwd(), propertiesFile.getPath())
}
warAction = utils.getMandatoryParameter(parameters, 'warAction', 'deploy')
}

def applicationName
def runtime
def runtimeVersion
def vmSize
if (deployMode == 'WAR_PARAMS') {
applicationName = utils.getMandatoryParameter(parameters, 'applicationName', null)
runtime = utils.getMandatoryParameter(parameters, 'runtime', null)
runtimeVersion = utils.getMandatoryParameter(parameters, 'runtimeVersion', null)
vmSize = utils.getMandatoryParameter(parameters, 'vmSize', 'lite')
warAction = utils.getMandatoryParameter(parameters, 'warAction', 'deploy')
}

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 = utils.getMandatoryParameter(parameters, 'deployHost', defaultDeployHost)
def deployAccount = utils.getMandatoryParameter(parameters, 'deployAccount', defaultDeployAccount)
def deployHost
def deployAccount
if (deployMode.equals('MTA') || deployMode.equals('WAR_PARAMS')) {
deployHost = utils.getMandatoryParameter(parameters, 'deployHost', defaultDeployHost)
deployAccount = utils.getMandatoryParameter(parameters, 'deployAccount', defaultDeployAccount)
}

def credentialsId = parameters.get('neoCredentialsId', defaultCredentialsId)

def neoExecutable = getNeoExecutable(parameters)

withCredentials([usernamePassword(
if (deployMode == 'MTA') {
withCredentials([usernamePassword(
credentialsId: credentialsId,
passwordVariable: 'password',
usernameVariable: 'username'
)]) {
sh """#!/bin/bash
"${neoExecutable}" deploy-mta \
usernameVariable: 'username')]) {
sh """#!/bin/bash
"${neoExecutable}" deploy-mta \
--user '${username}' \
--host '${deployHost}' \
--source "${archivePath.getAbsolutePath()}" \
--account '${deployAccount}' \
--password '${password}' \
--synchronous
"""
"""
}
}

if (deployMode == 'WAR_PARAMS') {
withCredentials([usernamePassword(
credentialsId: credentialsId,
passwordVariable: 'password',
usernameVariable: 'username')]) {
sh """#!/bin/bash
"${neoExecutable}" "${warAction}" \
--user '${username}' \
--password '${password}' \
--host '${deployHost}' \
--account ${deployAccount} \
--application '${applicationName}' \
--runtime '${runtime}' \
--runtime-version '${runtimeVersion}' \
--size '${vmSize}' \
--source '${archivePath.getAbsolutePath()}'
"""
}
}

if (deployMode == 'WAR_PROPERTIESFILE') {
withCredentials([usernamePassword(
credentialsId: credentialsId,
passwordVariable: 'password',
usernameVariable: 'username')]) {
sh """#!/bin/bash
"${neoExecutable}" "${warAction}" \
'${propertiesFile.getAbsolutePath()}' \
--user '${username}' \
--password '${password}' \
--source '${archivePath.getAbsolutePath()}'
"""
}
}
}
}
Expand Down

0 comments on commit 8784450

Please sign in to comment.