2018-09-21 16:55:31 +02:00
|
|
|
import static com.sap.piper.Prerequisites.checkScript
|
|
|
|
|
2018-10-04 17:06:42 +02:00
|
|
|
import com.sap.piper.ConfigurationHelper
|
2019-03-19 16:38:52 +02:00
|
|
|
import com.sap.piper.GenerateDocumentation
|
2018-10-08 11:30:42 +02:00
|
|
|
import com.sap.piper.GitUtils
|
2018-10-04 17:06:42 +02:00
|
|
|
import com.sap.piper.Utils
|
|
|
|
import com.sap.piper.k8s.ContainerMap
|
|
|
|
import groovy.transform.Field
|
|
|
|
import groovy.text.SimpleTemplateEngine
|
|
|
|
|
2018-11-29 10:54:05 +02:00
|
|
|
@Field String STEP_NAME = getClass().getName()
|
2018-10-25 14:01:44 +02:00
|
|
|
|
2019-03-19 16:38:52 +02:00
|
|
|
//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`
|
|
|
|
*/
|
2018-10-04 17:06:42 +02:00
|
|
|
'failOnError',
|
2019-03-19 16:38:52 +02:00
|
|
|
/**
|
|
|
|
* 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'
|
2018-10-04 17:06:42 +02:00
|
|
|
]
|
2019-03-19 16:38:52 +02:00
|
|
|
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS
|
2018-10-04 17:06:42 +02:00
|
|
|
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
|
|
|
|
|
2019-03-19 16:38:52 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2018-10-17 12:00:09 +02:00
|
|
|
void call(Map parameters = [:], Closure body) {
|
2018-10-04 17:06:42 +02:00
|
|
|
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters) {
|
2018-10-31 09:40:12 +02:00
|
|
|
def script = checkScript(this, parameters) ?: this
|
2018-10-04 17:06:42 +02:00
|
|
|
def utils = parameters?.juStabUtils ?: new Utils()
|
|
|
|
|
|
|
|
// load default & individual configuration
|
2018-10-18 11:02:09 +02:00
|
|
|
Map config = ConfigurationHelper.newInstance(this)
|
|
|
|
.loadStepDefaults()
|
2018-10-25 14:01:44 +02:00
|
|
|
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
|
2018-10-04 17:06:42 +02:00
|
|
|
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
|
|
|
|
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, STEP_CONFIG_KEYS)
|
|
|
|
.mixin(parameters, PARAMETER_KEYS)
|
|
|
|
.dependingOn('buildTool').mixin('dockerImage')
|
|
|
|
.dependingOn('buildTool').mixin('dockerName')
|
|
|
|
.dependingOn('buildTool').mixin('dockerWorkspace')
|
|
|
|
.use()
|
|
|
|
|
2019-01-21 09:47:34 +02:00
|
|
|
utils.pushToSWA([
|
|
|
|
step: STEP_NAME,
|
|
|
|
stepParamKey1: 'scriptMissing',
|
|
|
|
stepParam1: parameters?.script == null
|
|
|
|
], config)
|
2018-10-04 17:06:42 +02:00
|
|
|
|
|
|
|
dockerExecute(
|
|
|
|
script: script,
|
|
|
|
containerPortMappings: config.containerPortMappings,
|
2018-10-17 16:44:20 +02:00
|
|
|
dockerEnvVars: config.dockerEnvVars,
|
2018-10-04 17:06:42 +02:00
|
|
|
dockerImage: config.dockerImage,
|
|
|
|
dockerName: config.dockerName,
|
|
|
|
dockerWorkspace: config.dockerWorkspace,
|
|
|
|
sidecarEnvVars: config.sidecarEnvVars,
|
|
|
|
sidecarImage: config.sidecarImage,
|
|
|
|
sidecarName: config.sidecarName,
|
|
|
|
sidecarVolumeBind: config.sidecarVolumeBind
|
|
|
|
) {
|
|
|
|
try {
|
2018-10-08 11:30:42 +02:00
|
|
|
config.stashContent = config.testRepository
|
|
|
|
?[GitUtils.handleTestRepository(this, config)]
|
|
|
|
:utils.unstashAll(config.stashContent)
|
2018-10-04 17:06:42 +02:00
|
|
|
body()
|
|
|
|
} catch (err) {
|
|
|
|
if (config.failOnError) {
|
|
|
|
throw err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|