mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
Merge branch 'master' into pr/fixStageDoc
This commit is contained in:
commit
513ceee8cf
@ -2,82 +2,20 @@
|
||||
|
||||
## Description
|
||||
|
||||
In this step the ([Karma test runner](http://karma-runner.github.io)) is executed.
|
||||
|
||||
The step is using the `seleniumExecuteTest` step to spins up two containers in a Docker network:
|
||||
|
||||
- a Selenium/Chrome container (`selenium/standalone-chrome`)
|
||||
- a NodeJS container (`node:8-stretch`)
|
||||
|
||||
In the Docker network, the containers can be referenced by the values provided in `dockerName` and `sidecarName`, the default values are `karma` and `selenium`. These values must be used in the `hostname` properties of the test configuration ([Karma](https://karma-runner.github.io/1.0/config/configuration-file.html) and [WebDriver](https://github.com/karma-runner/karma-webdriver-launcher#usage)).
|
||||
|
||||
!!! note
|
||||
In a Kubernetes environment, the containers both need to be referenced with `localhost`.
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
- **running Karma tests** - have a NPM module with running tests executed with Karma
|
||||
- **configured WebDriver** - have the [`karma-webdriver-launcher`](https://github.com/karma-runner/karma-webdriver-launcher) package installed and a custom, WebDriver-based browser configured in Karma
|
||||
* **running Karma tests** - have a NPM module with running tests executed with Karma
|
||||
* **configured WebDriver** - have the [`karma-webdriver-launcher`](https://github.com/karma-runner/karma-webdriver-launcher) package installed and a custom, WebDriver-based browser configured in Karma
|
||||
|
||||
## Parameters
|
||||
|
||||
| parameter | mandatory | default | possible values |
|
||||
| ----------|-----------|---------|-----------------|
|
||||
|script|yes|||
|
||||
|containerPortMappings|no|`[node:8-stretch: [[containerPort: 9876, hostPort: 9876]]]`||
|
||||
|dockerEnvVars|no|`[ NO_PROXY: 'localhost,karma,$NO_PROXY', no_proxy: 'localhost,karma,$no_proxy']`||
|
||||
|dockerImage|no|`node:8-stretch`||
|
||||
|dockerName|no|`karma`||
|
||||
|dockerWorkspace|no|`/home/node`||
|
||||
|failOnError|no|||
|
||||
|installCommand|no|`npm install --quiet`||
|
||||
|modules|no|`['.']`||
|
||||
|runCommand|no|`npm run karma`||
|
||||
|sidecarEnvVars|no|`[ NO_PROXY: 'localhost,selenium,$NO_PROXY', no_proxy: 'localhost,selenium,$no_proxy']`||
|
||||
|sidecarImage|no|||
|
||||
|sidecarName|no|||
|
||||
|sidecarVolumeBind|no|||
|
||||
|stashContent|no|`['buildDescriptor', 'tests']`||
|
||||
|
||||
- `script` - defines the global script environment of the Jenkinsfile run. Typically `this` is passed to this parameter. This allows the function to access the [`commonPipelineEnvironment`](commonPipelineEnvironment.md) for storing the measured duration.
|
||||
- `containerPortMappings` - see step [dockerExecute](dockerExecute.md)
|
||||
- `dockerEnvVars` - see step [dockerExecute](dockerExecute.md)
|
||||
- `dockerImage` - see step [dockerExecute](dockerExecute.md)
|
||||
- `dockerName` - see step [dockerExecute](dockerExecute.md)
|
||||
- `dockerWorkspace` - see step [dockerExecute](dockerExecute.md)
|
||||
- `failOnError` - see step [seleniumExecuteTests](seleniumExecuteTests.md)
|
||||
- `installCommand` - the command that is executed to install dependencies
|
||||
- `modules` - define the paths of the modules to execute tests on
|
||||
- `runCommand` - the command that is executed to start the tests
|
||||
- `sidecarEnvVars` - see step [dockerExecute](dockerExecute.md)
|
||||
- `sidecarImage` - see step [dockerExecute](dockerExecute.md)
|
||||
- `sidecarName` - see step [dockerExecute](dockerExecute.md)
|
||||
- `sidecarVolumeBind` - see step [dockerExecute](dockerExecute.md)
|
||||
- `stashContent` - pass specific stashed that should be considered for the tests
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
|
||||
## Step configuration
|
||||
|
||||
We recommend to define values of step parameters via [config.yml file](../configuration.md).
|
||||
|
||||
In following sections the configuration is possible:
|
||||
|
||||
| parameter | general | step | stage |
|
||||
| ----------|---------|------|-------|
|
||||
|script||||
|
||||
|containerPortMappings|X|X|X|
|
||||
|dockerEnvVars|X|X|X|
|
||||
|dockerImage|X|X|X|
|
||||
|dockerName|X|X|X|
|
||||
|dockerWorkspace|X|X|X|
|
||||
|failOnError|X|X|X|
|
||||
|installCommand|X|X|X|
|
||||
|modules|X|X|X|
|
||||
|runCommand|X|X|X|
|
||||
|sidecarEnvVars|X|X|X|
|
||||
|sidecarImage|X|X|X|
|
||||
|sidecarName|X|X|X|
|
||||
|sidecarVolumeBind|X|X|X|
|
||||
|stashContent|X|X|X|
|
||||
Content here is generated from corresponnding step, see `vars`.
|
||||
|
||||
## Side effects
|
||||
|
||||
|
@ -9,25 +9,23 @@ class NeoCommandHelper {
|
||||
private Script step
|
||||
private DeployMode deployMode
|
||||
private Map deploymentConfiguration
|
||||
private String pathToNeoExecutable
|
||||
private String user
|
||||
private String password
|
||||
private String source
|
||||
|
||||
//Warning: Commands generated with this class can contain passwords and should only be used within the step withCredentials
|
||||
NeoCommandHelper(Script step, DeployMode deployMode, Map deploymentConfiguration, String pathToNeoExecutable,
|
||||
NeoCommandHelper(Script step, DeployMode deployMode, Map deploymentConfiguration,
|
||||
String user, String password, String source) {
|
||||
this.step = step
|
||||
this.deployMode = deployMode
|
||||
this.deploymentConfiguration = deploymentConfiguration
|
||||
this.pathToNeoExecutable = pathToNeoExecutable
|
||||
this.user = user
|
||||
this.password = password
|
||||
this.source = source
|
||||
}
|
||||
|
||||
private String prolog() {
|
||||
return "\"${pathToNeoExecutable}\""
|
||||
return 'neo.sh'
|
||||
}
|
||||
|
||||
String statusCommand() {
|
||||
|
@ -115,9 +115,11 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
|
||||
.commonPipelineEnvironment
|
||||
.configuration = [steps:
|
||||
[neoDeploy:
|
||||
[ host: 'hana.example.com',
|
||||
account: 'myTestAccount',
|
||||
]
|
||||
[neo:
|
||||
[ host: 'hana.example.com',
|
||||
account: 'myTestAccount',
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
|
||||
@ -139,7 +141,7 @@ class FioriOnCloudPlatformPipelineTest extends BasePiperTest {
|
||||
// the neo deploy call:
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher()
|
||||
.hasProlog("\"/opt/sap/neo/tools/neo.sh\" deploy-mta")
|
||||
.hasProlog("neo.sh deploy-mta")
|
||||
.hasSingleQuotedOption('host', 'hana\\.example\\.com')
|
||||
.hasSingleQuotedOption('account', 'myTestAccount')
|
||||
.hasSingleQuotedOption('password', 'terceSpot')
|
||||
|
@ -84,109 +84,10 @@ class NeoDeployTest extends BasePiperTest {
|
||||
helper.registerAllowedMethod('dockerExecute', [Map, Closure], null)
|
||||
helper.registerAllowedMethod('fileExists', [String], { s -> return new File(workspacePath, s).exists() })
|
||||
helper.registerAllowedMethod('pwd', [], { return workspacePath })
|
||||
mockShellCommands()
|
||||
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [neoDeploy: [neo: [host: 'test.deploy.host.com', account: 'trialuser123']]]]
|
||||
}
|
||||
|
||||
@Test
|
||||
void straightForwardTestCompatibilityConfiguration(){
|
||||
shellRule.setReturnValue(JenkinsShellCallRule.Type.REGEX, '.* status .*', 'Status: STARTED')
|
||||
|
||||
nullScript.commonPipelineEnvironment.configuration = [
|
||||
steps: [
|
||||
neoDeploy: [
|
||||
host: 'test.deploy.host.com',
|
||||
account: 'trialuser123',
|
||||
neoCredentialsId: 'myCredentialsId'
|
||||
]]]
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
archivePath: warArchiveName,
|
||||
deployMode: 'warParams',
|
||||
applicationName: 'testApp',
|
||||
runtime: 'neo-javaee6-wp',
|
||||
runtimeVersion: '2.125',
|
||||
warAction: 'rolling-update',
|
||||
vmSize: 'lite')
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" rolling-update")
|
||||
.hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com')
|
||||
.hasSingleQuotedOption('account', 'trialuser123')
|
||||
.hasSingleQuotedOption('application', 'testApp')
|
||||
.hasSingleQuotedOption('runtime', 'neo-javaee6-wp')
|
||||
.hasSingleQuotedOption('runtime-version', '2\\.125')
|
||||
.hasSingleQuotedOption('size', 'lite')
|
||||
.hasSingleQuotedOption('user', 'anonymous')
|
||||
.hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*')
|
||||
.hasSingleQuotedOption('source', '.*\\.war'))
|
||||
}
|
||||
|
||||
@Test
|
||||
void straightForwardTestConfigViaConfigProperties() {
|
||||
|
||||
boolean buildStatusHasBeenSet = false
|
||||
boolean notifyOldConfigFrameworkUsed = false
|
||||
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
nullScript.commonPipelineEnvironment.configuration = [:]
|
||||
|
||||
nullScript.currentBuild = [setResult: { buildStatusHasBeenSet = true }]
|
||||
|
||||
def utils = new Utils() {
|
||||
void pushToSWA(Map parameters, Map config) {
|
||||
notifyOldConfigFrameworkUsed = parameters.stepParam4
|
||||
}
|
||||
}
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: archiveName,
|
||||
neo: [credentialsId: 'myCredentialsId'],
|
||||
utils: utils
|
||||
)
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" deploy-mta")
|
||||
.hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com')
|
||||
.hasSingleQuotedOption('account', 'trialuser123')
|
||||
.hasOption('synchronous', '')
|
||||
.hasSingleQuotedOption('user', 'anonymous')
|
||||
.hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*')
|
||||
.hasSingleQuotedOption('source', '.*'))
|
||||
|
||||
assert !buildStatusHasBeenSet
|
||||
assert notifyOldConfigFrameworkUsed
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConfigViaConfigPropertiesSetsBuildToUnstable() {
|
||||
|
||||
def buildStatus = 'SUCCESS'
|
||||
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('DEPLOY_HOST', 'test.deploy.host.com')
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'trialuser123')
|
||||
nullScript.commonPipelineEnvironment.configuration = [:]
|
||||
|
||||
nullScript.currentBuild = [setResult: { r -> buildStatus = r }]
|
||||
|
||||
System.setProperty('com.sap.piper.featureFlag.buildUnstableWhenOldConfigFrameworkIsUsedByNeoDeploy',
|
||||
Boolean.TRUE.toString())
|
||||
|
||||
try {
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: archiveName,
|
||||
neo:[credentialsId: 'myCredentialsId'],
|
||||
utils: utils
|
||||
)
|
||||
} finally {
|
||||
System.clearProperty('com.sap.piper.featureFlag.buildUnstableWhenOldConfigFrameworkIsUsedByNeoDeploy')
|
||||
}
|
||||
|
||||
assert buildStatus == 'UNSTABLE'
|
||||
}
|
||||
|
||||
@Test
|
||||
void straightForwardTestConfigViaConfiguration() {
|
||||
|
||||
@ -205,7 +106,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
)
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" deploy-mta")
|
||||
new CommandLineMatcher().hasProlog("neo.sh deploy-mta")
|
||||
.hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com')
|
||||
.hasSingleQuotedOption('account', 'trialuser123')
|
||||
.hasOption('synchronous', '')
|
||||
@ -231,7 +132,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
)
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" deploy-mta")
|
||||
new CommandLineMatcher().hasProlog("neo.sh deploy-mta")
|
||||
.hasSingleQuotedOption('host', 'configuration-frwk\\.deploy\\.host\\.com')
|
||||
.hasSingleQuotedOption('account', 'configurationFrwkUser123')
|
||||
.hasOption('synchronous', '')
|
||||
@ -246,7 +147,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
stepRule.step.neoDeploy(script: nullScript)
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" deploy-mta")
|
||||
new CommandLineMatcher().hasProlog("neo.sh deploy-mta")
|
||||
.hasSingleQuotedOption('source', 'archive.mtar'))
|
||||
}
|
||||
|
||||
@ -257,7 +158,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
source: "archive.mtar")
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" deploy-mta")
|
||||
new CommandLineMatcher().hasProlog("neo.sh deploy-mta")
|
||||
.hasSingleQuotedOption('source', 'archive.mtar'))
|
||||
}
|
||||
|
||||
@ -282,7 +183,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
)
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" deploy-mta")
|
||||
new CommandLineMatcher().hasProlog("neo.sh deploy-mta")
|
||||
.hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com')
|
||||
.hasSingleQuotedOption('account', 'trialuser123')
|
||||
.hasOption('synchronous', '')
|
||||
@ -292,69 +193,6 @@ class NeoDeployTest extends BasePiperTest {
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void neoHomeNotSetTest() {
|
||||
|
||||
mockHomeVariablesNotSet()
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: archiveName
|
||||
)
|
||||
|
||||
assert shellRule.shell.find { c -> c.contains('"neo.sh" deploy-mta') }
|
||||
assert loggingRule.log.contains('SAP Cloud Platform Console Client is on PATH.')
|
||||
assert loggingRule.log.contains("Using SAP Cloud Platform Console Client 'neo.sh'.")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void neoHomeAsParameterTest() {
|
||||
|
||||
mockHomeVariablesNotSet()
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: archiveName,
|
||||
neo:[credentialsId: 'myCredentialsId'],
|
||||
neoHome: '/param/neo'
|
||||
)
|
||||
|
||||
assert shellRule.shell.find { c -> c = "\"/param/neo/tools/neo.sh\" deploy-mta" }
|
||||
assert loggingRule.log.contains("SAP Cloud Platform Console Client home '/param/neo' retrieved from configuration.")
|
||||
assert loggingRule.log.contains("Using SAP Cloud Platform Console Client '/param/neo/tools/neo.sh'.")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void neoHomeFromEnvironmentTest() {
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: archiveName
|
||||
)
|
||||
|
||||
assert shellRule.shell.find { c -> c.contains("\"/opt/neo/tools/neo.sh\" deploy-mta") }
|
||||
assert loggingRule.log.contains("SAP Cloud Platform Console Client home '/opt/neo' retrieved from environment.")
|
||||
assert loggingRule.log.contains("Using SAP Cloud Platform Console Client '/opt/neo/tools/neo.sh'.")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void neoHomeFromCustomStepConfigurationTest() {
|
||||
|
||||
mockHomeVariablesNotSet()
|
||||
|
||||
nullScript.commonPipelineEnvironment.configuration = [steps: [neoDeploy: [neo: [host: 'test.deploy.host.com', account: 'trialuser123'], neoHome: '/config/neo']]]
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: archiveName
|
||||
)
|
||||
|
||||
assert shellRule.shell.find { c -> c = "\"/config/neo/tools/neo.sh\" deploy-mta" }
|
||||
assert loggingRule.log.contains("SAP Cloud Platform Console Client home '/config/neo' retrieved from configuration.")
|
||||
assert loggingRule.log.contains("Using SAP Cloud Platform Console Client '/config/neo/tools/neo.sh'.")
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void archiveNotProvidedTest() {
|
||||
|
||||
@ -392,7 +230,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
stepRule.step.neoDeploy(script: nullScript, source: archiveName, deployMode: 'mta')
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" deploy-mta")
|
||||
new CommandLineMatcher().hasProlog("neo.sh deploy-mta")
|
||||
.hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com')
|
||||
.hasSingleQuotedOption('account', 'trialuser123')
|
||||
.hasOption('synchronous', '')
|
||||
@ -417,7 +255,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
source: warArchiveName)
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" deploy")
|
||||
new CommandLineMatcher().hasProlog("neo.sh deploy")
|
||||
.hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com')
|
||||
.hasSingleQuotedOption('account', 'trialuser123')
|
||||
.hasSingleQuotedOption('application', 'testApp')
|
||||
@ -448,7 +286,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
)
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" rolling-update")
|
||||
new CommandLineMatcher().hasProlog("neo.sh rolling-update")
|
||||
.hasSingleQuotedOption('host', 'test\\.deploy\\.host\\.com')
|
||||
.hasSingleQuotedOption('account', 'trialuser123')
|
||||
.hasSingleQuotedOption('application', 'testApp')
|
||||
@ -478,7 +316,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher()
|
||||
.hasProlog("\"/opt/neo/tools/neo.sh\" deploy")
|
||||
.hasProlog("neo.sh deploy")
|
||||
.hasSingleQuotedOption('application', 'testApp'))
|
||||
}
|
||||
|
||||
@ -541,7 +379,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
)
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" deploy")
|
||||
new CommandLineMatcher().hasProlog("neo.sh deploy")
|
||||
.hasArgument("config.properties")
|
||||
.hasSingleQuotedOption('user', 'defaultUser')
|
||||
.hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*')
|
||||
@ -566,7 +404,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
])
|
||||
|
||||
Assert.assertThat(shellRule.shell,
|
||||
new CommandLineMatcher().hasProlog("\"/opt/neo/tools/neo.sh\" rolling-update")
|
||||
new CommandLineMatcher().hasProlog("neo.sh rolling-update")
|
||||
.hasArgument('config.properties')
|
||||
.hasSingleQuotedOption('user', 'defaultUser')
|
||||
.hasSingleQuotedOption('password', '\\*\\*\\*\\*\\*\\*\\*\\*')
|
||||
@ -654,57 +492,4 @@ class NeoDeployTest extends BasePiperTest {
|
||||
size: 'lite'
|
||||
])
|
||||
}
|
||||
|
||||
@Test
|
||||
void deployHostProvidedAsDeprecatedParameterTest() {
|
||||
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: archiveName,
|
||||
deployHost: "my.deploy.host.com"
|
||||
)
|
||||
|
||||
assert loggingRule.log.contains("[WARNING][neoDeploy] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead.")
|
||||
}
|
||||
|
||||
@Test
|
||||
void deployAccountProvidedAsDeprecatedParameterTest() {
|
||||
|
||||
nullScript.commonPipelineEnvironment.setConfigProperty('CI_DEPLOY_ACCOUNT', 'configPropsUser123')
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: archiveName,
|
||||
neo: [
|
||||
host: "my.deploy.host.com",
|
||||
],
|
||||
deployAccount: "myAccount"
|
||||
)
|
||||
|
||||
assert loggingRule.log.contains("Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead.")
|
||||
}
|
||||
|
||||
private mockShellCommands() {
|
||||
String javaVersion = '''openjdk version \"1.8.0_121\"
|
||||
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-1~bpo8+1-b13)
|
||||
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)'''
|
||||
shellRule.setReturnValue(Type.REGEX, '.*java -version.*', javaVersion)
|
||||
|
||||
String neoVersion = '''SAP Cloud Platform Console Client
|
||||
SDK version : 3.39.10
|
||||
Runtime : neo-java-web'''
|
||||
shellRule.setReturnValue(Type.REGEX, '.*neo.sh version.*', neoVersion)
|
||||
|
||||
shellRule.setReturnValue(Type.REGEX, '.*JAVA_HOME.*', '/opt/java')
|
||||
shellRule.setReturnValue(Type.REGEX, '.*NEO_HOME.*', '/opt/neo')
|
||||
shellRule.setReturnValue(Type.REGEX, '.*which java.*', 0)
|
||||
shellRule.setReturnValue(Type.REGEX, '.*which neo.*', 0)
|
||||
}
|
||||
|
||||
private mockHomeVariablesNotSet() {
|
||||
shellRule.setReturnValue(Type.REGEX, '.*JAVA_HOME.*', '')
|
||||
shellRule.setReturnValue(Type.REGEX, '.*NEO_HOME.*', '')
|
||||
shellRule.setReturnValue(Type.REGEX, '.*which java.*', 0)
|
||||
shellRule.setReturnValue(Type.REGEX, '.*which neo.*', 0)
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ class NeoCommandHelperTest extends BasePiperTest {
|
||||
String source = (deployMode == DeployMode.MTA) ? 'file.mta' : 'file.war'
|
||||
String username = 'username'
|
||||
String password = 'password'
|
||||
String neoExecutable = '/path/tools/neo.sh';
|
||||
|
||||
nullScript.STEP_NAME="neoDeploy"
|
||||
|
||||
@ -42,7 +41,6 @@ class NeoCommandHelperTest extends BasePiperTest {
|
||||
nullScript,
|
||||
deployMode,
|
||||
deploymentConfiguration,
|
||||
neoExecutable,
|
||||
username,
|
||||
password,
|
||||
source
|
||||
@ -52,7 +50,7 @@ class NeoCommandHelperTest extends BasePiperTest {
|
||||
@Test
|
||||
void testStatusCommand() {
|
||||
String actual = getTestFixture(DeployMode.WAR_PARAMS).statusCommand()
|
||||
String expected = "\"/path/tools/neo.sh\" status --host 'host_value' --account 'account_value' " +
|
||||
String expected = "neo.sh status --host 'host_value' --account 'account_value' " +
|
||||
"--application 'application_value' --user 'username' --password 'password'"
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
@ -60,14 +58,14 @@ class NeoCommandHelperTest extends BasePiperTest {
|
||||
@Test
|
||||
void testStatusCommandForProperties() {
|
||||
String actual = getTestFixture(DeployMode.WAR_PROPERTIES_FILE).statusCommand()
|
||||
String expected = "\"/path/tools/neo.sh\" status file.properties --user 'username' --password 'password'"
|
||||
String expected = "neo.sh status file.properties --user 'username' --password 'password'"
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRollingUpdateCommand() {
|
||||
String actual = getTestFixture(DeployMode.WAR_PARAMS).rollingUpdateCommand()
|
||||
String basicCommand = "\"/path/tools/neo.sh\" rolling-update --host 'host_value' --account 'account_value' " +
|
||||
String basicCommand = "neo.sh rolling-update --host 'host_value' --account 'account_value' " +
|
||||
"--application 'application_value' --user 'username' --password 'password' --source 'file.war'"
|
||||
|
||||
Assert.assertTrue(actual.contains(basicCommand))
|
||||
@ -81,14 +79,14 @@ class NeoCommandHelperTest extends BasePiperTest {
|
||||
@Test
|
||||
void testRollingUpdateCommandForProperties() {
|
||||
String actual = getTestFixture(DeployMode.WAR_PROPERTIES_FILE).rollingUpdateCommand()
|
||||
String expected = "\"/path/tools/neo.sh\" rolling-update file.properties --user 'username' --password 'password' --source 'file.war' "
|
||||
String expected = "neo.sh rolling-update file.properties --user 'username' --password 'password' --source 'file.war' "
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeployCommand() {
|
||||
String actual = getTestFixture(DeployMode.WAR_PARAMS).deployCommand()
|
||||
String basicCommand = "\"/path/tools/neo.sh\" deploy --host 'host_value' --account 'account_value' " +
|
||||
String basicCommand = "neo.sh deploy --host 'host_value' --account 'account_value' " +
|
||||
"--application 'application_value' --user 'username' --password 'password' --source 'file.war'"
|
||||
|
||||
Assert.assertTrue(actual.contains(basicCommand))
|
||||
@ -102,14 +100,14 @@ class NeoCommandHelperTest extends BasePiperTest {
|
||||
@Test
|
||||
void testDeployCommandForProperties() {
|
||||
String actual = getTestFixture(DeployMode.WAR_PROPERTIES_FILE).deployCommand()
|
||||
String expected = "\"/path/tools/neo.sh\" deploy file.properties --user 'username' --password 'password' --source 'file.war' "
|
||||
String expected = "neo.sh deploy file.properties --user 'username' --password 'password' --source 'file.war' "
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRestartCommand() {
|
||||
String actual = getTestFixture(DeployMode.WAR_PARAMS).restartCommand()
|
||||
String expected = "\"/path/tools/neo.sh\" restart --synchronous --host 'host_value' --account 'account_value' " +
|
||||
String expected = "neo.sh restart --synchronous --host 'host_value' --account 'account_value' " +
|
||||
"--application 'application_value' --user 'username' --password 'password'"
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
@ -117,14 +115,14 @@ class NeoCommandHelperTest extends BasePiperTest {
|
||||
@Test
|
||||
void testRestartCommandForProperties() {
|
||||
String actual = getTestFixture(DeployMode.WAR_PROPERTIES_FILE).restartCommand()
|
||||
String expected = "\"/path/tools/neo.sh\" restart --synchronous file.properties --user 'username' --password 'password'"
|
||||
String expected = "neo.sh restart --synchronous file.properties --user 'username' --password 'password'"
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
@Test
|
||||
void deployMta() {
|
||||
String actual = getTestFixture(DeployMode.MTA).deployMta()
|
||||
String expected = "\"/path/tools/neo.sh\" deploy-mta --synchronous --host 'host_value' --account 'account_value' " +
|
||||
String expected = "neo.sh deploy-mta --synchronous --host 'host_value' --account 'account_value' " +
|
||||
"--user 'username' --password 'password' --source 'file.mta'"
|
||||
Assert.assertEquals(expected, actual)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import static com.sap.piper.Prerequisites.checkScript
|
||||
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.GenerateDocumentation
|
||||
import com.sap.piper.GitUtils
|
||||
import com.sap.piper.Utils
|
||||
|
||||
@ -9,34 +10,67 @@ import groovy.transform.Field
|
||||
|
||||
@Field String STEP_NAME = getClass().getName()
|
||||
@Field Set GENERAL_CONFIG_KEYS = [
|
||||
/** port mappings required for containers. This will only take effect inside a Kubernetes pod, format [[containerPort: 1111, hostPort: 1111]] */
|
||||
/**
|
||||
* Map which defines per docker image the port mappings, e.g. `containerPortMappings: ['selenium/standalone-chrome': [[name: 'selPort', containerPort: 4444, hostPort: 4444]]]`.
|
||||
*/
|
||||
'containerPortMappings',
|
||||
/** envVars to be set in the execution container if required */
|
||||
/** A map of environment variables to set in the container, e.g. [http_proxy:'proxy:8080']. */
|
||||
'dockerEnvVars',
|
||||
/** Docker image for code execution */
|
||||
/** The name of the docker image that should be used. If empty, Docker is not used and the command is executed directly on the Jenkins system. */
|
||||
'dockerImage',
|
||||
/** name of the Docker container. If not on Kubernetes pod, this will define the network-alias to the NPM container and is thus required for accessing the server, example http://karma:9876 (default). */
|
||||
/**
|
||||
* Kubernetes only:
|
||||
* Name of the container launching `dockerImage`.
|
||||
* SideCar only:
|
||||
* Name of the container in local network.
|
||||
*/
|
||||
'dockerName',
|
||||
/** user home directory for Docker execution. This will only take effect inside a Kubernetes pod. */
|
||||
/**
|
||||
* Kubernetes only:
|
||||
* Specifies a dedicated user home directory for the container which will be passed as value for environment variable `HOME`.
|
||||
*/
|
||||
'dockerWorkspace',
|
||||
/**
|
||||
* With `failOnError` the behavior in case tests fail can be defined.
|
||||
* @possibleValues `true`, `false`
|
||||
*/
|
||||
'failOnError',
|
||||
/** The command that is executed to install the test tool. */
|
||||
'installCommand',
|
||||
/** Define the paths of the modules to execute tests on. */
|
||||
'modules',
|
||||
/** The command that is executed to start the tests. */
|
||||
'runCommand',
|
||||
/** envVars to be set in Selenium container if required */
|
||||
/** A map of environment variables to set in the sidecar container, similar to `dockerEnvVars`. */
|
||||
'sidecarEnvVars',
|
||||
/** image for Selenium execution which runs as sidecar to dockerImage */
|
||||
/** The name of the docker image of the sidecar container. If empty, no sidecar container is started. */
|
||||
'sidecarImage',
|
||||
/** name of the Selenium container. If not on Kubernetes pod, this will define the network-alias to the Selenium container and is thus required for accessing the server, example http://selenium:4444 (default) */
|
||||
/**
|
||||
* as `dockerName` for the sidecar container
|
||||
*/
|
||||
'sidecarName',
|
||||
/** volume bind. This will not take effect in Kubernetes pod. */
|
||||
/** Volumes that should be mounted into the sidecar container. */
|
||||
'sidecarVolumeBind',
|
||||
/** list of stash names which are required to be unstashed before test run */
|
||||
/** If specific stashes should be considered for the tests, their names need to be passed via the parameter `stashContent`. */
|
||||
'stashContent'
|
||||
]
|
||||
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS
|
||||
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
||||
|
||||
/**
|
||||
* In this step the ([Karma test runner](http://karma-runner.github.io)) is executed.
|
||||
*
|
||||
* The step is using the `seleniumExecuteTest` step to spin up two containers in a Docker network:
|
||||
*
|
||||
* * a Selenium/Chrome container (`selenium/standalone-chrome`)
|
||||
* * a NodeJS container (`node:8-stretch`)
|
||||
*
|
||||
* In the Docker network, the containers can be referenced by the values provided in `dockerName` and `sidecarName`, the default values are `karma` and `selenium`. These values must be used in the `hostname` properties of the test configuration ([Karma](https://karma-runner.github.io/1.0/config/configuration-file.html) and [WebDriver](https://github.com/karma-runner/karma-webdriver-launcher#usage)).
|
||||
*
|
||||
* !!! note
|
||||
* In a Kubernetes environment, the containers both need to be referenced with `localhost`.
|
||||
*/
|
||||
@GenerateDocumentation
|
||||
void call(Map parameters = [:]) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
final script = checkScript(this, parameters) ?: this
|
||||
|
@ -1,6 +1,5 @@
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.Utils
|
||||
import com.sap.piper.tools.ToolDescriptor
|
||||
import com.sap.piper.tools.neo.DeployMode
|
||||
import com.sap.piper.tools.neo.NeoCommandHelper
|
||||
import com.sap.piper.tools.neo.WarAction
|
||||
@ -25,21 +24,6 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
'warAction'
|
||||
])
|
||||
|
||||
@Field Map CONFIG_KEY_COMPATIBILITY = [
|
||||
neo : [
|
||||
host : 'host',
|
||||
account : 'account',
|
||||
application : 'applicationName',
|
||||
credentialsId : 'neoCredentialsId',
|
||||
propertiesFile: 'propertiesFile',
|
||||
runtime : 'runtime',
|
||||
runtimeVersion: 'runtimeVersion',
|
||||
size : 'vmSize'
|
||||
|
||||
],
|
||||
source: 'archivePath'
|
||||
]
|
||||
|
||||
void call(parameters = [:]) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
|
||||
@ -49,17 +33,14 @@ void call(parameters = [:]) {
|
||||
|
||||
prepareDefaultValues script: script
|
||||
|
||||
Map stepCompatibilityConfiguration = handleCompatibility(script, parameters)
|
||||
|
||||
// load default & individual configuration
|
||||
Map configuration = ConfigurationHelper.newInstance(this)
|
||||
.loadStepDefaults()
|
||||
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
||||
.mixin(stepCompatibilityConfiguration)
|
||||
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS, CONFIG_KEY_COMPATIBILITY)
|
||||
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName ?: env.STAGE_NAME, STEP_CONFIG_KEYS, CONFIG_KEY_COMPATIBILITY)
|
||||
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
||||
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName ?: env.STAGE_NAME, STEP_CONFIG_KEYS)
|
||||
.addIfEmpty('source', script.commonPipelineEnvironment.getMtarFilePath())
|
||||
.mixin(parameters, PARAMETER_KEYS, CONFIG_KEY_COMPATIBILITY)
|
||||
.mixin(parameters, PARAMETER_KEYS)
|
||||
.withMandatoryProperty('neo')
|
||||
.withMandatoryProperty('source')
|
||||
.withMandatoryProperty('neo/credentialsId')
|
||||
@ -74,12 +55,8 @@ void call(parameters = [:]) {
|
||||
stepParam2: configuration.warAction == 'rolling-update'?'blue-green':'standard', // ['deploy', 'deploy-mta', 'rolling-update']
|
||||
stepParamKey3: 'scriptMissing',
|
||||
stepParam3: parameters?.script == null,
|
||||
stepParamKey4: 'legacyConfig',
|
||||
stepParam4: !stepCompatibilityConfiguration.isEmpty(),
|
||||
], configuration)
|
||||
|
||||
ToolDescriptor neo = new ToolDescriptor('SAP Cloud Platform Console Client', 'NEO_HOME', 'neoHome', '/tools/', 'neo.sh', null, 'version')
|
||||
ToolDescriptor java = new ToolDescriptor('Java', 'JAVA_HOME', '', '/bin/', 'java', '1.8.0', '-version 2>&1')
|
||||
|
||||
withCredentials([usernamePassword(
|
||||
credentialsId: configuration.neo.credentialsId,
|
||||
@ -94,19 +71,12 @@ void call(parameters = [:]) {
|
||||
dockerEnvVars: configuration.dockerEnvVars,
|
||||
dockerOptions: configuration.dockerOptions
|
||||
) {
|
||||
|
||||
neo.verify(this, configuration)
|
||||
java.verify(this, configuration)
|
||||
|
||||
String neoExecutable = neo.getToolExecutable(script, configuration)
|
||||
|
||||
DeployMode deployMode = DeployMode.fromString(configuration.deployMode)
|
||||
|
||||
NeoCommandHelper neoCommandHelper = new NeoCommandHelper(
|
||||
this,
|
||||
deployMode,
|
||||
configuration.neo,
|
||||
neoExecutable,
|
||||
NEO_USERNAME,
|
||||
NEO_PASSWORD,
|
||||
configuration.source
|
||||
@ -165,61 +135,6 @@ private boolean isAppRunning(NeoCommandHelper commandHelper) {
|
||||
return status.contains('Status: STARTED')
|
||||
}
|
||||
|
||||
private handleCompatibility(script, parameters) {
|
||||
final Map neoCompatibilityConfiguration = [:]
|
||||
|
||||
// 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][${STEP_NAME}] A deprecated configuration framework is used for configuring parameter 'DEPLOY_HOST'. This configuration framework will be removed in future versions."
|
||||
neoCompatibilityConfiguration.put('host', defaultDeployHost)
|
||||
}
|
||||
|
||||
def defaultDeployAccount = script.commonPipelineEnvironment.getConfigProperty('CI_DEPLOY_ACCOUNT')
|
||||
if (defaultDeployAccount) {
|
||||
echo "[WARNING][${STEP_NAME}] A deprecated configuration framework is used for configuring parameter 'DEPLOY_ACCOUNT'. This configuration framekwork will be removed in future versions."
|
||||
neoCompatibilityConfiguration.put('account', defaultDeployAccount)
|
||||
}
|
||||
|
||||
if (parameters.deployHost && !parameters.host) {
|
||||
echo "[WARNING][${STEP_NAME}] Deprecated parameter 'deployHost' is used. This will not work anymore in future versions. Use parameter 'host' instead."
|
||||
parameters.put('host', parameters.deployHost)
|
||||
}
|
||||
|
||||
if (parameters.deployAccount && !parameters.account) {
|
||||
echo "[WARNING][${STEP_NAME}] Deprecated parameter 'deployAccount' is used. This will not work anymore in future versions. Use parameter 'account' instead."
|
||||
parameters.put('account', parameters.deployAccount)
|
||||
}
|
||||
|
||||
def credId = script.commonPipelineEnvironment.getConfigProperty('neoCredentialsId')
|
||||
if (credId && !parameters.neoCredentialsId) {
|
||||
echo "[WARNING][${STEP_NAME}] Deprecated parameter 'neoCredentialsId' from old configuration framework is used. This will not work anymore in future versions."
|
||||
parameters.put('neoCredentialsId', credId)
|
||||
}
|
||||
|
||||
if (!neoCompatibilityConfiguration.isEmpty()) {
|
||||
echo "[WARNING][$STEP_NAME] You are using a deprecated configuration framework. This will be removed in " +
|
||||
'futureVersions.\nAdd snippet below to \'./pipeline/config.yml\' and remove ' +
|
||||
'file \'.pipeline/configuration.properties\'.\n' +
|
||||
"""|steps:
|
||||
| neoDeploy:
|
||||
| neo:
|
||||
| host: ${neoCompatibilityConfiguration.get('host', '<Add host here>')}
|
||||
| account: ${neoCompatibilityConfiguration.get('account', '<Add account here>')}
|
||||
""".stripMargin()
|
||||
|
||||
if (Boolean.getBoolean('com.sap.piper.featureFlag.buildUnstableWhenOldConfigFrameworkIsUsedByNeoDeploy')) {
|
||||
script.currentBuild.setResult('UNSTABLE')
|
||||
echo "[WARNING][$STEP_NAME] Build has been set to unstable since old config framework is used."
|
||||
}
|
||||
return [neo: neoCompatibilityConfiguration]
|
||||
}
|
||||
|
||||
return [:]
|
||||
}
|
||||
|
||||
private assertPasswordRules(String password) {
|
||||
if (password.startsWith("@")) {
|
||||
error("Your password for the deployment to SAP Cloud Platform contains characters which are not " +
|
||||
|
@ -14,7 +14,7 @@ void call(Map parameters = [:]) {
|
||||
|
||||
handlePipelineStepErrors (stepName: 'toolValidate', stepParameters: parameters) {
|
||||
|
||||
echo '[WARNING][toolValidate] This step is deprecated, and it will be removed in future versions. Validation is automatically done inside the steps.'
|
||||
echo '[WARNING][toolValidate] This step is deprecated, and it will be removed in future versions.'
|
||||
|
||||
def tool = parameters.tool
|
||||
def home = parameters.home
|
||||
|
Loading…
Reference in New Issue
Block a user