mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
Merge remote-tracking branch 'github/master' into HEAD
This commit is contained in:
commit
ad41c27458
@ -1,18 +1,6 @@
|
||||
# seleniumExecuteTests
|
||||
# ${docGenStepName}
|
||||
|
||||
## Description
|
||||
|
||||
Enables UI test execution with Selenium in a sidecar container.
|
||||
|
||||
The step executes a closure (see example below) connecting to a sidecar container with a Selenium Server.
|
||||
|
||||
When executing in a
|
||||
|
||||
* local Docker environment, please make sure to set Selenium host to **`selenium`** in your tests.
|
||||
* Kubernetes environment, plese make sure to set Seleniums host to **`localhost`** in your tests.
|
||||
|
||||
!!! note "Proxy Environments"
|
||||
If work in an environment containing a proxy, please make sure that `localhost`/`selenium` is added to your proxy exclusion list, e.g. via environment variable `NO_PROXY` & `no_proxy`. You can pass those via parameters `dockerEnvVars` and `sidecarEnvVars` directly to the containers if required.
|
||||
## ${docGenDescription}
|
||||
|
||||
## Prerequisites
|
||||
|
||||
@ -76,66 +64,9 @@ webdriverio
|
||||
});
|
||||
```
|
||||
|
||||
## Parameters
|
||||
## ${docGenParameters}
|
||||
|
||||
| parameter | mandatory | default | possible values |
|
||||
| ----------|-----------|---------|-----------------|
|
||||
|script|yes|||
|
||||
|buildTool|no|`npm`|`maven`, `npm`|
|
||||
|containerPortMappings|no|`[selenium/standalone-chrome:[[containerPort:4444, hostPort:4444]]]`||
|
||||
|dockerEnvVars|no|||
|
||||
|dockerImage|no|buildTool=`maven`: `maven:3.5-jdk-8`<br />buildTool=`npm`: `node:8-stretch`<br />||
|
||||
|dockerName|no|buildTool=`maven`: `maven`<br />buildTool=`npm`: `npm`<br />||
|
||||
|dockerWorkspace|no|buildTool=`maven`: <br />buildTool=`npm`: `/home/node`<br />||
|
||||
|failOnError|no|`true`||
|
||||
|gitBranch|no|||
|
||||
|gitSshKeyCredentialsId|no|``||
|
||||
|sidecarEnvVars|no|||
|
||||
|sidecarImage|no|`selenium/standalone-chrome`||
|
||||
|sidecarName|no|`selenium`||
|
||||
|sidecarVolumeBind|no|`[/dev/shm:/dev/shm]`||
|
||||
|stashContent|no|<ul><li>`tests`</li></ul>||
|
||||
|testRepository|no|||
|
||||
|
||||
* `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.
|
||||
* `buildTool` defines the build tool to be used for the test execution.
|
||||
* `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` specifies if the step should fail in case the execution of the body of this step fails.
|
||||
* `sidecarEnvVars`, see step [dockerExecute](dockerExecute.md)
|
||||
* `sidecarImage`, see step [dockerExecute](dockerExecute.md)
|
||||
* `sidecarName`, see step [dockerExecute](dockerExecute.md)
|
||||
* `sidecarVolumeBind`, see step [dockerExecute](dockerExecute.md)
|
||||
* If specific stashes should be considered for the tests, you can pass this via parameter `stashContent`
|
||||
* In case the test implementation is stored in a different repository than the code itself, you can define the repository containing the tests using parameter `testRepository` and if required `gitBranch` (for a different branch than master) and `gitSshKeyCredentialsId` (for protected repositories). For protected repositories the testRepository needs to contain the ssh git url.
|
||||
|
||||
## 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||||
|
||||
|buildTool||X|X|
|
||||
|containerPortMappings|X|X|X|
|
||||
|dockerEnvVars|X|X|X|
|
||||
|dockerImage|X|X|X|
|
||||
|dockerName|X|X|X|
|
||||
|dockerWorkspace|X|X|X|
|
||||
|failOnError|X|X|X|
|
||||
|gitBranch|X|X|X|
|
||||
|gitSshKeyCredentialsId|X|X|X|
|
||||
|sidecarEnvVars|X|X|X|
|
||||
|sidecarImage|X|X|X|
|
||||
|sidecarName|X|X|X|
|
||||
|sidecarVolumeBind|X|X|X|
|
||||
|stashContent|X|X|X|
|
||||
|testRepository|X|X|X|
|
||||
## ${docGenConfiguration}
|
||||
|
||||
## Side effects
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.sap.piper.tools.neo
|
||||
|
||||
import com.sap.piper.BashUtils
|
||||
import com.sap.piper.ConfigurationHelper
|
||||
import com.sap.piper.StepAssertions
|
||||
|
||||
class NeoCommandHelper {
|
||||
@ -58,20 +57,11 @@ class NeoCommandHelper {
|
||||
"/acc/${properties.account}/app/${properties.application}/dashboard"
|
||||
}
|
||||
|
||||
ConfigurationHelper configurationHelper = ConfigurationHelper.newInstance(step, deploymentConfiguration)
|
||||
|
||||
configurationHelper
|
||||
.withMandatoryProperty('host')
|
||||
.withMandatoryProperty('account')
|
||||
|
||||
if (deployMode == DeployMode.MTA) {
|
||||
return "https://account.${deploymentConfiguration.host}/cockpit#" +
|
||||
"/acc/${deploymentConfiguration.account}/mtas"
|
||||
}
|
||||
|
||||
configurationHelper
|
||||
.withMandatoryProperty('application')
|
||||
|
||||
return "https://account.${deploymentConfiguration.host}/cockpit#" +
|
||||
"/acc/${deploymentConfiguration.account}/app/${deploymentConfiguration.application}/dashboard"
|
||||
}
|
||||
@ -82,17 +72,9 @@ class NeoCommandHelper {
|
||||
return "${properties.host}/${properties.account}/${properties.application}"
|
||||
}
|
||||
|
||||
ConfigurationHelper configurationHelper = ConfigurationHelper.newInstance(step, deploymentConfiguration)
|
||||
configurationHelper
|
||||
.withMandatoryProperty('host')
|
||||
.withMandatoryProperty('account')
|
||||
|
||||
|
||||
String resource = "${deploymentConfiguration.host}/${deploymentConfiguration.account}"
|
||||
|
||||
if (deployMode == DeployMode.WAR_PARAMS) {
|
||||
configurationHelper
|
||||
.withMandatoryProperty('application')
|
||||
|
||||
resource += "/${deploymentConfiguration.application}"
|
||||
}
|
||||
@ -113,17 +95,10 @@ class NeoCommandHelper {
|
||||
return "${deploymentConfiguration.propertiesFile} ${usernamePassword}"
|
||||
}
|
||||
|
||||
ConfigurationHelper configurationHelper = ConfigurationHelper.newInstance(step, deploymentConfiguration)
|
||||
configurationHelper
|
||||
.withMandatoryProperty('host')
|
||||
.withMandatoryProperty('account')
|
||||
|
||||
String targetArgs = "--host ${BashUtils.quoteAndEscape(deploymentConfiguration.host)}"
|
||||
targetArgs += " --account ${BashUtils.quoteAndEscape(deploymentConfiguration.account)}"
|
||||
|
||||
if (deployMode == DeployMode.WAR_PARAMS) {
|
||||
configurationHelper
|
||||
.withMandatoryProperty('application')
|
||||
|
||||
targetArgs += " --application ${BashUtils.quoteAndEscape(deploymentConfiguration.application)}"
|
||||
}
|
||||
@ -136,13 +111,8 @@ class NeoCommandHelper {
|
||||
return ""
|
||||
}
|
||||
|
||||
ConfigurationHelper configurationHelper = ConfigurationHelper.newInstance(step, deploymentConfiguration)
|
||||
|
||||
String args = ""
|
||||
configurationHelper.withMandatoryProperty('runtime')
|
||||
args += " --runtime ${BashUtils.quoteAndEscape(deploymentConfiguration.runtime)}"
|
||||
|
||||
configurationHelper.withMandatoryProperty('runtimeVersion')
|
||||
args += " --runtime-version ${BashUtils.quoteAndEscape(deploymentConfiguration.runtimeVersion)}"
|
||||
|
||||
if (deploymentConfiguration.size) {
|
||||
|
@ -220,7 +220,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
void scriptNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR host')
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR neo/host')
|
||||
|
||||
nullScript.commonPipelineEnvironment.configuration = [:]
|
||||
|
||||
@ -418,7 +418,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
void applicationNameNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR application')
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR neo/application')
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: warArchiveName,
|
||||
@ -434,7 +434,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
void runtimeNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtime')
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR neo/runtime')
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: warArchiveName,
|
||||
@ -449,7 +449,7 @@ class NeoDeployTest extends BasePiperTest {
|
||||
void runtimeVersionNotProvidedTest() {
|
||||
|
||||
thrown.expect(Exception)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR runtimeVersion')
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR neo/runtimeVersion')
|
||||
|
||||
stepRule.step.neoDeploy(script: nullScript,
|
||||
source: warArchiveName,
|
||||
|
@ -34,18 +34,30 @@ void call(parameters = [:]) {
|
||||
prepareDefaultValues script: script
|
||||
|
||||
// load default & individual configuration
|
||||
Map configuration = ConfigurationHelper.newInstance(this)
|
||||
ConfigurationHelper configHelper = ConfigurationHelper.newInstance(this)
|
||||
.loadStepDefaults()
|
||||
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
||||
.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)
|
||||
.withMandatoryProperty('neo')
|
||||
.withMandatoryProperty('neo/host')
|
||||
.withMandatoryProperty('neo/account')
|
||||
.withMandatoryProperty('source')
|
||||
.withMandatoryProperty('neo/credentialsId')
|
||||
.withPropertyInValues('deployMode', DeployMode.stringValues())
|
||||
.use()
|
||||
|
||||
Map configuration = configHelper.use()
|
||||
|
||||
DeployMode deployMode = DeployMode.fromString(configuration.deployMode)
|
||||
|
||||
def isWarParamsDeployMode = { deployMode == DeployMode.WAR_PARAMS }
|
||||
|
||||
configHelper
|
||||
.withMandatoryProperty('neo/application', null, isWarParamsDeployMode)
|
||||
.withMandatoryProperty('neo/runtime', null, isWarParamsDeployMode)
|
||||
.withMandatoryProperty('neo/runtimeVersion', null, isWarParamsDeployMode)
|
||||
|
||||
|
||||
utils.pushToSWA([
|
||||
step: STEP_NAME,
|
||||
@ -71,8 +83,6 @@ void call(parameters = [:]) {
|
||||
dockerEnvVars: configuration.dockerEnvVars,
|
||||
dockerOptions: configuration.dockerOptions
|
||||
) {
|
||||
DeployMode deployMode = DeployMode.fromString(configuration.deployMode)
|
||||
|
||||
NeoCommandHelper neoCommandHelper = new NeoCommandHelper(
|
||||
this,
|
||||
deployMode,
|
||||
|
@ -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
|
||||
import com.sap.piper.k8s.ContainerMap
|
||||
@ -9,28 +10,70 @@ import groovy.text.SimpleTemplateEngine
|
||||
|
||||
@Field String STEP_NAME = getClass().getName()
|
||||
|
||||
@Field GENERAL_CONFIG_KEYS = STEP_CONFIG_KEYS
|
||||
|
||||
@Field Set STEP_CONFIG_KEYS = [
|
||||
'buildTool', //defines the tool which is used for executing the tests
|
||||
'containerPortMappings', //port mappings required for containers. This will only take effect inside a Kubernetes pod, format [[containerPort: 1111, hostPort: 1111]]
|
||||
'dockerEnvVars', //envVars to be set in the execution container if required
|
||||
'dockerImage', //Docker image for code execution
|
||||
'dockerName', //name of the Docker container. This will only take effect inside a Kubernetes pod.
|
||||
'dockerWorkspace', //user home directory for Docker execution. This will only take effect inside a Kubernetes pod.
|
||||
//TODO: limit parameter visibility
|
||||
@Field Set GENERAL_CONFIG_KEYS = [
|
||||
/**
|
||||
* Defines the tool which is used for executing the tests
|
||||
* @possibleValues `'maven'`, `'npm'`
|
||||
*/
|
||||
'buildTool',
|
||||
/** @see dockerExecute */
|
||||
'containerPortMappings',
|
||||
/** @see dockerExecute */
|
||||
'dockerEnvVars',
|
||||
/** @see dockerExecute */
|
||||
'dockerImage',
|
||||
/** @see dockerExecute */
|
||||
'dockerName',
|
||||
/** @see dockerExecute */
|
||||
'dockerWorkspace',
|
||||
/**
|
||||
* With `failOnError` the behavior in case tests fail can be defined.
|
||||
* @possibleValues `true`, `false`
|
||||
*/
|
||||
'failOnError',
|
||||
'gitBranch', //only if testRepository is used: branch of testRepository. Default is master
|
||||
'gitSshKeyCredentialsId', //only if testRepository is used: ssh credentials id in case a protected testRepository is used
|
||||
'sidecarEnvVars', //envVars to be set in Selenium container if required
|
||||
'sidecarImage', //image for Selenium execution which runs as sidecar to dockerImage
|
||||
'sidecarName', //name of the Selenium container. If not on Kubernetes pod, this will define the name of the link to the Selenium container and is thus required for accessing the server, example http://selenium:4444 (default)
|
||||
'sidecarVolumeBind', //volume bind. This will not take effect in Kubernetes pod.
|
||||
'stashContent', //list of stash names which are required to be unstashed before test run
|
||||
'testRepository' //if tests are in a separate repository, git url can be defined. For protected repositories the git ssh url is required
|
||||
/**
|
||||
* Only if `testRepository` is provided: Branch of testRepository, defaults to master.
|
||||
*/
|
||||
'gitBranch',
|
||||
/**
|
||||
* Only if `testRepository` is provided: Credentials for a protected testRepository
|
||||
* @possibleValues Jenkins credentials id
|
||||
*/
|
||||
'gitSshKeyCredentialsId',
|
||||
/** @see dockerExecute */
|
||||
'sidecarEnvVars',
|
||||
/** @see dockerExecute */
|
||||
'sidecarImage',
|
||||
/** @see dockerExecute */
|
||||
'sidecarName',
|
||||
/** @see dockerExecute */
|
||||
'sidecarVolumeBind',
|
||||
/** @see dockerExecute */
|
||||
'stashContent',
|
||||
/**
|
||||
* Define an additional repository where the test implementation is located.
|
||||
* For protected repositories the `testRepository` needs to contain the ssh git url.
|
||||
*/
|
||||
'testRepository'
|
||||
]
|
||||
|
||||
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS
|
||||
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
||||
|
||||
/**
|
||||
* Enables UI test execution with Selenium in a sidecar container.
|
||||
*
|
||||
* The step executes a closure (see example below) connecting to a sidecar container with a Selenium Server.
|
||||
*
|
||||
* When executing in a
|
||||
*
|
||||
* * local Docker environment, please make sure to set Selenium host to **`selenium`** in your tests.
|
||||
* * Kubernetes environment, plese make sure to set Seleniums host to **`localhost`** in your tests.
|
||||
*
|
||||
* !!! note "Proxy Environments"
|
||||
* If work in an environment containing a proxy, please make sure that `localhost`/`selenium` is added to your proxy exclusion list, e.g. via environment variable `NO_PROXY` & `no_proxy`. You can pass those via parameters `dockerEnvVars` and `sidecarEnvVars` directly to the containers if required.
|
||||
*/
|
||||
@GenerateDocumentation
|
||||
void call(Map parameters = [:], Closure body) {
|
||||
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
||||
def script = checkScript(this, parameters) ?: this
|
||||
|
@ -11,33 +11,22 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
@Field String STEP_NAME = getClass().getName()
|
||||
|
||||
@Field Set GENERAL_CONFIG_KEYS = [
|
||||
/**
|
||||
* In case a `testRepository` is provided and it is protected, access credentials (as Jenkins credentials) can be provided with `gitSshKeyCredentialsId`. **Note: In case of using a protected repository, `testRepository` should include the ssh link to the repository.**
|
||||
* @possibleValues Jenkins credentialId
|
||||
*/
|
||||
/** @see seleniumExecuteTests */
|
||||
'gitSshKeyCredentialsId'
|
||||
]
|
||||
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([
|
||||
/**
|
||||
* A map of environment variables to set in the container, e.g. [http_proxy:'proxy:8080'].
|
||||
*/
|
||||
/** @see dockerExecute */
|
||||
'dockerEnvVars',
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
/** @see dockerExecute */
|
||||
'dockerImage',
|
||||
/**
|
||||
* Only relevant for Kubernetes case: Specifies a dedicated user home directory for the container which will be passed as value for environment variable `HOME`.
|
||||
*/
|
||||
/** @see dockerExecute */
|
||||
'dockerWorkspace',
|
||||
/**
|
||||
* With `failOnError` the behavior in case tests fail can be defined.
|
||||
* @possibleValues `true`, `false`
|
||||
*/
|
||||
'failOnError',
|
||||
/**
|
||||
* In case a `testRepository` is provided the branch in this repository can be specified with `gitBranch`.
|
||||
*/
|
||||
/** @see seleniumExecuteTests */
|
||||
'gitBranch',
|
||||
/**
|
||||
* The command that is executed to install the test tool.
|
||||
@ -55,25 +44,17 @@ import static com.sap.piper.Prerequisites.checkScript
|
||||
* The port of the selenium hub. The value is only needed for the `runCommand`.
|
||||
*/
|
||||
'seleniumPort',
|
||||
/**
|
||||
* A map of environment variables to set in the sidecar container, similar to `dockerEnvVars`.
|
||||
*/
|
||||
/** @see dockerExecute */
|
||||
'sidecarEnvVars',
|
||||
/**
|
||||
* The name of the docker image of the sidecar container. If empty, no sidecar container is started.
|
||||
*/
|
||||
/** @see dockerExecute */
|
||||
'sidecarImage',
|
||||
/**
|
||||
* If specific stashes should be considered for the tests, their names need to be passed via the parameter `stashContent`.
|
||||
*/
|
||||
/** @see dockerExecute */
|
||||
'stashContent',
|
||||
/**
|
||||
* This allows to set specific options for the UIVeri5 execution. Details can be found [in the UIVeri5 documentation](https://github.com/SAP/ui5-uiveri5/blob/master/docs/config/config.md#configuration).
|
||||
*/
|
||||
'testOptions',
|
||||
/**
|
||||
* With `testRepository` the tests can be loaded from another reposirory.
|
||||
*/
|
||||
/** @see seleniumExecuteTests */
|
||||
'testRepository',
|
||||
/**
|
||||
* The `testServerUrl` is passed as environment variable `TARGET_SERVER_URL` to the test execution.
|
||||
|
Loading…
Reference in New Issue
Block a user