mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-12 10:55:20 +02:00
Merge pull request #41 from marcusholl/pr/neoDeployWithNewConfigFramework
neo deploy with new config framework and introduce docker execute
This commit is contained in:
commit
437abcf225
@ -12,21 +12,20 @@ Deploys an Application to SAP Cloud Platform (SAP CP) using the SAP Cloud Platfo
|
||||
|
||||
* **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`.
|
||||
`<neoRoot>/tools` needs to be in the `PATH`. This step is also capable of triggering the neo deploy tool provided inside a docker image.
|
||||
|
||||
* **Java 8 or higher** - needed by the *Neo-Java-Web-SDK*
|
||||
|
||||
## Parameters when using MTA deployment method (default - MTA)
|
||||
| parameter | mandatory | default | possible values |
|
||||
| -------------------|-----------|----------------------------------------------------------------------------------------------|-------------------------------------------------|
|
||||
| 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 | |
|
||||
|
||||
| `script` | yes | | |
|
||||
| `archivePath` | yes | | |
|
||||
| `deployHost` | no | `'account'` from step configuration `'neoDeploy'`, or propertey `'DEPLOY_HOST'` from `commonPipelineEnvironment` (deprecated) | |
|
||||
| `deployAccount` | no | `'host'` from step configuration `'neoDeploy'`, or property `'CI_DEPLOY_ACCOUNT'` from `commonPipelineEnvironment` (deprecated) | |
|
||||
| `neoCredentialsId` | no | `'neoCredentialsId'` from step configuration `'neoDeploy'` or hard coded value `'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 |
|
||||
| -------------------|-----------|----------------------------------------------------------------------------------------------|-------------------------------------------------|
|
||||
@ -93,3 +92,14 @@ none
|
||||
```groovy
|
||||
neoDeploy script: this, archivePath: 'path/to/archiveFile.mtar', credentialsId: 'my-credentials-id'
|
||||
```
|
||||
|
||||
Example configuration:
|
||||
|
||||
```
|
||||
steps:
|
||||
<...>
|
||||
neoDeploy:
|
||||
|
||||
account: <myDeployAccount>
|
||||
host: hana.example.org
|
||||
```
|
||||
|
@ -8,4 +8,8 @@ steps:
|
||||
dockerImage: 'maven:3.5-jdk-7'
|
||||
influxWriteData:
|
||||
influxServer: 'jenkins'
|
||||
|
||||
neoDeploy:
|
||||
deployMode: 'mta'
|
||||
warAction: 'deploy'
|
||||
vmSize: 'lite'
|
||||
neoCredentialsId: 'CI_CREDENTIALS_ID'
|
||||
|
@ -1,5 +1,6 @@
|
||||
#!groovy
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
import com.sap.piper.DefaultValueCache
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
@ -31,6 +32,13 @@ class InfluxWriteDataTest extends BasePipelineTest {
|
||||
@Before
|
||||
void init() throws Exception {
|
||||
|
||||
//
|
||||
// Currently we have dependencies between the tests since
|
||||
// DefaultValueCache is a singleton which keeps its status
|
||||
// for all the tests. Depending on the test order we fail.
|
||||
// As long as this status remains we need:
|
||||
DefaultValueCache.reset()
|
||||
|
||||
//reset stepMap
|
||||
stepMap = [:]
|
||||
//reset fileMap
|
||||
|
@ -1,4 +1,5 @@
|
||||
import hudson.AbortException
|
||||
|
||||
import org.junit.rules.TemporaryFolder
|
||||
|
||||
import com.lesfurets.jenkins.unit.BasePipelineTest
|
||||
@ -46,6 +47,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
propertiesFileName = 'config.properties'
|
||||
archiveName = "archive.mtar"
|
||||
|
||||
helper.registerAllowedMethod('dockerExecute', [Map, Closure], null)
|
||||
helper.registerAllowedMethod('error', [String], { s -> throw new AbortException(s) })
|
||||
helper.registerAllowedMethod('fileExists', [String], { s -> return new File(workspacePath, s).exists() })
|
||||
helper.registerAllowedMethod('usernamePassword', [Map], { m -> return m })
|
||||
@ -76,7 +78,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
|
||||
|
||||
@Test
|
||||
void straightForwardTest() {
|
||||
void straightForwardTestConfigViaConfigProperties() {
|
||||
|
||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||
|
||||
@ -90,7 +92,54 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void straightForwardTestConfigViaConfiguration() {
|
||||
|
||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
|
||||
cpe.configuration.put('steps', [neoDeploy: [host: 'test.deploy.host.com',
|
||||
account: 'trialuser123']])
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void straightForwardTestConfigViaConfigurationAndViaConfigProperties() {
|
||||
|
||||
//configuration via configurationFramekwork superseds.
|
||||
binding.getVariable('env')['NEO_HOME'] = '/opt/neo'
|
||||
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
|
||||
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'configProperties.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
|
||||
cpe.configuration.put('steps', [neoDeploy: [host: 'configuration-frwk.deploy.host.com',
|
||||
account: 'configurationFrwkUser123']])
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
archivePath: archiveName,
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'configuration-frwk\.deploy\.host\.com' --account 'configurationFrwkUser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
|
||||
@ -105,6 +154,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
|
||||
thrown.expect(MissingPropertyException)
|
||||
thrown.expectMessage('No such property: username')
|
||||
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
@ -130,7 +180,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
archivePath: archiveName
|
||||
)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
@ -148,7 +198,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
archivePath: archiveName
|
||||
)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "neo" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous/
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "neo.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/
|
||||
|
||||
assert jlr.log.contains("Using Neo executable from PATH.")
|
||||
}
|
||||
@ -168,10 +218,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
neoHome: '/etc/neo'
|
||||
)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/etc\/neo\/tools\/neo\.sh" deploy-mta --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous.*/
|
||||
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/etc/neo/tools/neo.sh\" retrieved from parameters.")
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/etc\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'anonymous' --password '\*\*\*\*\*\*\*\*' --source ".*"/
|
||||
}
|
||||
|
||||
|
||||
@ -179,7 +226,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
void archiveNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR archivePath')
|
||||
thrown.expectMessage('Archive path not configured (parameter "archivePath").')
|
||||
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
@ -192,7 +239,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
void wrongArchivePathProvidedTest() {
|
||||
|
||||
thrown.expect(AbortException)
|
||||
thrown.expectMessage("Archive cannot be found with parameter archivePath: '")
|
||||
thrown.expectMessage("Archive cannot be found")
|
||||
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
@ -208,7 +255,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
new File(workspacePath, archiveName) << "dummy archive"
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR deployHost')
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR host')
|
||||
|
||||
neoDeployScript.call(archivePath: archiveName)
|
||||
}
|
||||
@ -224,7 +271,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe], archivePath: archiveName, deployMode: 'mta')
|
||||
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*" --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous.*/
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy-mta --host 'test\.deploy\.host\.com' --account 'trialuser123' --synchronous --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*"/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@ -236,10 +283,6 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
cpe.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
cpe.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
|
||||
def appName = 'testApp'
|
||||
def runtime = 'neo-javaee6-wp'
|
||||
def runtimeVersion = '2.125'
|
||||
|
||||
neoDeployScript.call(script: [commonPipelineEnvironment: cpe],
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
@ -249,7 +292,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
warAction: 'deploy',
|
||||
archivePath: warArchiveName)
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite'/
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite' --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@ -270,7 +313,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
warAction: 'rolling-update',
|
||||
vmSize: 'lite')
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite'/
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update --host 'test\.deploy\.host\.com' --account 'trialuser123' --application 'testApp' --runtime 'neo-javaee6-wp' --runtime-version '2\.125' --size 'lite' --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@ -290,7 +333,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
warAction: 'deploy',
|
||||
vmSize: 'lite')
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" .*\.properties/
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" deploy .*\.properties --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
@ -310,7 +353,7 @@ class NeoDeploymentTest extends BasePipelineTest {
|
||||
warAction: 'rolling-update',
|
||||
vmSize: 'lite')
|
||||
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war" .*\.properties/
|
||||
assert jscr.shell[0] =~ /#!\/bin\/bash "\/opt\/neo\/tools\/neo\.sh" rolling-update .*\.properties --user 'defaultUser' --password '\*\*\*\*\*\*\*\*' --source ".*\.war"/
|
||||
assert jlr.log.contains("[neoDeploy] Neo executable \"/opt/neo/tools/neo.sh\" retrieved from environment.")
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,12 @@ def call(Map parameters = [:], body) {
|
||||
echo "[WARNING][${STEP_NAME}] No docker environment found (command 'which docker' did not return with '0'). Configured docker image '${dockerImage}' will not be used."
|
||||
dockerImage = null
|
||||
}
|
||||
|
||||
returnCode = sh script: 'docker ps -q > /dev/null', returnStatus: true
|
||||
if(returnCode != 0) {
|
||||
echo "[WARNING][$STEP_NAME] Cannot connect to docker daemon (command 'docker ps' did not return with '0'). Configured docker image '${dockerImage}' will not be used."
|
||||
dockerImage = null
|
||||
}
|
||||
}
|
||||
|
||||
if(!dockerImage){
|
||||
|
@ -1,74 +1,167 @@
|
||||
import com.sap.piper.Utils
|
||||
|
||||
import com.sap.piper.ConfigurationLoader
|
||||
import com.sap.piper.ConfigurationMerger
|
||||
import com.sap.piper.ConfigurationType
|
||||
|
||||
def call(parameters = [:]) {
|
||||
|
||||
handlePipelineStepErrors (stepName: 'neoDeploy', stepParameters: parameters) {
|
||||
def stepName = 'neoDeploy'
|
||||
|
||||
List parameterKeys = [
|
||||
'applicationName',
|
||||
'archivePath',
|
||||
'account',
|
||||
'deployMode',
|
||||
'dockerEnvVars',
|
||||
'dockerImage',
|
||||
'dockerOptions',
|
||||
'host',
|
||||
'neoCredentialsId',
|
||||
'neoHome',
|
||||
'propertiesFile',
|
||||
'runtime',
|
||||
'runtimeVersion',
|
||||
'vmSize',
|
||||
'warAction'
|
||||
]
|
||||
|
||||
List stepConfigurationKeys = [
|
||||
'account',
|
||||
'dockerEnvVars',
|
||||
'dockerImage',
|
||||
'dockerOptions',
|
||||
'host',
|
||||
'neoCredentialsId',
|
||||
'neoHome'
|
||||
]
|
||||
|
||||
handlePipelineStepErrors (stepName: stepName, stepParameters: parameters) {
|
||||
|
||||
def script = parameters?.script ?: [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
def utils = new Utils()
|
||||
def script = parameters.script
|
||||
if (script == null){
|
||||
script = [commonPipelineEnvironment: commonPipelineEnvironment]
|
||||
|
||||
prepareDefaultValues script: script
|
||||
|
||||
final Map stepConfiguration = [:]
|
||||
|
||||
// Backward compatibility: ensure old configuration is taken into account
|
||||
// The old configuration in not stage / step specific
|
||||
|
||||
def defaultDeployHost = script.commonPipelineEnvironment.getConfigProperty('DEPLOY_HOST')
|
||||
if(defaultDeployHost) {
|
||||
echo "[WARNING][${stepName}] A deprecated configuration framework is used for configuring parameter 'DEPLOY_HOST'. This configuration framework will be removed in future versions."
|
||||
stepConfiguration.put('host', defaultDeployHost)
|
||||
}
|
||||
|
||||
def archivePath = utils.getMandatoryParameter(parameters, 'archivePath', null)
|
||||
if (!fileExists(archivePath)){
|
||||
error "Archive cannot be found with parameter archivePath: '${archivePath}'."
|
||||
def defaultDeployAccount = script.commonPipelineEnvironment.getConfigProperty('CI_DEPLOY_ACCOUNT')
|
||||
if(defaultDeployAccount) {
|
||||
echo "[WARNING][${stepName}] A deprecated configuration framework is used for configuring parameter 'DEPLOY_ACCOUNT'. This configuration framekwork will be removed in future versions."
|
||||
stepConfiguration.put('account', defaultDeployAccount)
|
||||
}
|
||||
|
||||
def deployMode = utils.getMandatoryParameter(parameters, 'deployMode', 'mta')
|
||||
if(parameters.DEPLOY_HOST && !parameters.host) {
|
||||
echo "[WARNING][${stepName}] Deprecated parameter 'DEPLOY_HOST' is used. This will not work anymore in future versions. Use parameter 'host' instead."
|
||||
parameters.put('host', parameters.DEPLOY_HOST)
|
||||
}
|
||||
|
||||
if(parameters.CI_DEPLOY_ACCOUNT && !parameters.account) {
|
||||
echo "[WARNING][${stepName}] Deprecated parameter 'CI_DEPLOY_ACCOUNT' is used. This will not work anymore in future versions. Use parameter 'account' instead."
|
||||
parameters.put('account', parameters.CI_DEPLOY_ACCOUNT)
|
||||
}
|
||||
|
||||
// Backward compatibility end
|
||||
|
||||
stepConfiguration.putAll(ConfigurationLoader.stepConfiguration(script, stepName))
|
||||
|
||||
Map configuration = ConfigurationMerger.merge(parameters, parameterKeys,
|
||||
stepConfiguration, stepConfigurationKeys,
|
||||
ConfigurationLoader.defaultStepConfiguration(script, stepName))
|
||||
|
||||
def archivePath = configuration.archivePath
|
||||
if(archivePath?.trim()) {
|
||||
if (!fileExists(archivePath)) {
|
||||
error "Archive cannot be found with parameter archivePath: '${archivePath}'."
|
||||
}
|
||||
} else {
|
||||
error "Archive path not configured (parameter \"archivePath\")."
|
||||
}
|
||||
|
||||
def deployHost
|
||||
def deployAccount
|
||||
def credentialsId = configuration.get('neoCredentialsId', '')
|
||||
def deployMode = configuration.deployMode
|
||||
def warAction
|
||||
def propertiesFile
|
||||
def applicationName
|
||||
def runtime
|
||||
def runtimeVersion
|
||||
def vmSize
|
||||
|
||||
if (deployMode != 'mta' && deployMode != 'warParams' && deployMode != 'warPropertiesFile') {
|
||||
throw new Exception("[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')
|
||||
warAction = utils.getMandatoryParameter(configuration, 'warAction')
|
||||
if (warAction != 'deploy' && warAction != 'rolling-update') {
|
||||
throw new Exception("[neoDeploy] Invalid warAction = '${warAction}'. Valid 'warAction' values are: 'deploy' and 'rolling-update'.")
|
||||
}
|
||||
}
|
||||
|
||||
if (deployMode == 'warPropertiesFile') {
|
||||
propertiesFile = utils.getMandatoryParameter(parameters, 'propertiesFile', null)
|
||||
propertiesFile = utils.getMandatoryParameter(configuration, 'propertiesFile')
|
||||
if (!fileExists(propertiesFile)){
|
||||
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')
|
||||
applicationName = utils.getMandatoryParameter(configuration, 'applicationName')
|
||||
runtime = utils.getMandatoryParameter(configuration, 'runtime')
|
||||
runtimeVersion = utils.getMandatoryParameter(configuration, 'runtimeVersion')
|
||||
vmSize = configuration.vmSize
|
||||
if (vmSize != 'lite' && vmSize !='pro' && vmSize != 'prem' && vmSize != 'prem-plus') {
|
||||
throw new Exception("[neoDeploy] Invalid vmSize = '${vmSize}'. Valid 'vmSize' values are: 'lite', 'pro', 'prem' and 'prem-plus'.")
|
||||
}
|
||||
}
|
||||
|
||||
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'
|
||||
if (deployMode.equals('mta') || deployMode.equals('warParams')) {
|
||||
deployHost = utils.getMandatoryParameter(configuration, 'host')
|
||||
deployAccount = utils.getMandatoryParameter(configuration, 'account')
|
||||
}
|
||||
|
||||
def deployHost
|
||||
def deployAccount
|
||||
def neoExecutable = getNeoExecutable(configuration)
|
||||
|
||||
if (deployMode.equals('mta') || deployMode.equals('warParams')) {
|
||||
deployHost = utils.getMandatoryParameter(parameters, 'deployHost', defaultDeployHost)
|
||||
deployAccount = utils.getMandatoryParameter(parameters, 'deployAccount', defaultDeployAccount)
|
||||
def neoDeployScript
|
||||
|
||||
if (deployMode == 'mta') {
|
||||
neoDeployScript =
|
||||
"""#!/bin/bash
|
||||
"${neoExecutable}" deploy-mta \
|
||||
--host '${deployHost}' \
|
||||
--account '${deployAccount}' \
|
||||
--synchronous"""
|
||||
}
|
||||
|
||||
def credentialsId = parameters.get('neoCredentialsId', defaultCredentialsId)
|
||||
if (deployMode == 'warParams') {
|
||||
neoDeployScript =
|
||||
"""#!/bin/bash
|
||||
"${neoExecutable}" ${warAction} \
|
||||
--host '${deployHost}' \
|
||||
--account '${deployAccount}' \
|
||||
--application '${applicationName}' \
|
||||
--runtime '${runtime}' \
|
||||
--runtime-version '${runtimeVersion}' \
|
||||
--size '${vmSize}'"""
|
||||
}
|
||||
|
||||
def neoExecutable = getNeoExecutable(parameters)
|
||||
if (deployMode == 'warPropertiesFile') {
|
||||
neoDeployScript =
|
||||
"""#!/bin/bash
|
||||
"${neoExecutable}" ${warAction} \
|
||||
${propertiesFile}"""
|
||||
}
|
||||
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: credentialsId,
|
||||
@ -80,48 +173,25 @@ def call(parameters = [:]) {
|
||||
--password '${password}' \
|
||||
--source "${archivePath}" \
|
||||
"""
|
||||
dockerExecute(dockerImage: configuration.get('dockerImage'),
|
||||
dockerEnvVars: configuration.get('dockerEnvVars'),
|
||||
dockerOptions: configuration.get('dockerOptions')) {
|
||||
|
||||
if (deployMode == 'mta') {
|
||||
sh """#!/bin/bash
|
||||
"${neoExecutable}" deploy-mta \
|
||||
${commonDeployParams} \
|
||||
--host '${deployHost}' \
|
||||
--account '${deployAccount}' \
|
||||
--synchronous
|
||||
"""
|
||||
}
|
||||
|
||||
if (deployMode == 'warParams') {
|
||||
sh """#!/bin/bash
|
||||
"${neoExecutable}" ${warAction} \
|
||||
${commonDeployParams} \
|
||||
--host '${deployHost}' \
|
||||
--account '${deployAccount}' \
|
||||
--application '${applicationName}' \
|
||||
--runtime '${runtime}' \
|
||||
--runtime-version '${runtimeVersion}' \
|
||||
--size '${vmSize}'
|
||||
"""
|
||||
}
|
||||
|
||||
if (deployMode == 'warPropertiesFile') {
|
||||
sh """#!/bin/bash
|
||||
"${neoExecutable}" ${warAction} \
|
||||
${commonDeployParams} \
|
||||
${propertiesFile}
|
||||
sh """${neoDeployScript} \
|
||||
${commonDeployParams}
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private getNeoExecutable(parameters) {
|
||||
private getNeoExecutable(configuration) {
|
||||
|
||||
def neoExecutable = 'neo' // default, if nothing below applies maybe it is the path.
|
||||
def neoExecutable = 'neo.sh' // 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."
|
||||
if (configuration.neoHome) {
|
||||
neoExecutable = "${configuration.neoHome}/tools/neo.sh"
|
||||
echo "[neoDeploy] Neo executable \"${neoExecutable}\" retrieved from configuration."
|
||||
return neoExecutable
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user