1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-12 10:55:20 +02:00
sap-jenkins-library/vars/dockerExecute.groovy

380 lines
14 KiB
Groovy
Raw Normal View History

import static com.sap.piper.Prerequisites.checkScript
import com.cloudbees.groovy.cps.NonCPS
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
import com.sap.piper.ConfigurationHelper
import com.sap.piper.GenerateDocumentation
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
import com.sap.piper.JenkinsUtils
import com.sap.piper.Utils
import com.sap.piper.k8s.ContainerMap
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
import groovy.transform.Field
2018-06-07 13:58:32 +02:00
@Field def STEP_NAME = getClass().getName()
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
@Field def PLUGIN_ID_DOCKER_WORKFLOW = 'docker-workflow'
@Field Set GENERAL_CONFIG_KEYS = [
/**
*
*/
'jenkinsKubernetes'
]
@Field Set STEP_CONFIG_KEYS = GENERAL_CONFIG_KEYS.plus([
/**
* Kubernetes only:
* Allows to specify start command for container created with dockerImage parameter to overwrite Piper default (`/usr/bin/tail -f /dev/null`).
*/
'containerCommand',
/**
* Map which defines per docker image the port mappings, e.g. `containerPortMappings: ['selenium/standalone-chrome': [[name: 'selPort', containerPort: 4444, hostPort: 4444]]]`.
*/
'containerPortMappings',
/**
* Kubernetes only:
* Allows to specify the shell to be used for execution of commands.
*/
'containerShell',
/**
* Environment variables to set in the container, e.g. [http_proxy: 'proxy:8080'].
*/
'dockerEnvVars',
/**
* 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',
/**
* Kubernetes only:
* Name of the container launching `dockerImage`.
* SideCar only:
* Name of the container in local network.
*/
'dockerName',
/**
* Docker options to be set when starting the container (List or String).
*/
'dockerOptions',
/**
* Volumes that should be mounted into the container.
*/
'dockerVolumeBind',
/**
* Set this to 'false' to bypass a docker image pull. Usefull during development process. Allows testing of images which are available in the local registry only.
*/
'dockerPullImage',
/**
* Kubernetes only:
* Specifies a dedicated user home directory for the container which will be passed as value for environment variable `HOME`.
*/
'dockerWorkspace',
/**
* as `dockerEnvVars` for the sidecar container
*/
'sidecarEnvVars',
/**
* as `dockerImage` for the sidecar container
*/
'sidecarImage',
/**
* as `dockerName` for the sidecar container
*/
'sidecarName',
/**
* as `dockerOptions` for the sidecar container
*/
'sidecarOptions',
/**
* as `dockerVolumeBind` for the sidecar container
*/
'sidecarVolumeBind',
/**
* Set this to 'false' to bypass a docker image pull. Usefull during development process. Allows testing of images which are available in the local registry only.
*/
'sidecarPullImage',
/**
* as `dockerWorkspace` for the sidecar container
*/
'sidecarWorkspace',
/**
* Command executed inside the container which returns exit code 0 when the container is ready to be used.
*/
'sidecarReadyCommand',
/**
* Specific stashes that should be considered for the step execution.
*/
'stashContent'
])
@Field Set PARAMETER_KEYS = STEP_CONFIG_KEYS
2018-05-14 17:11:27 +02:00
/**
* Executes a closure inside a docker container with the specified docker image.
* The workspace is mounted into the docker image.
* Proxy environment variables defined on the Jenkins machine are also available in the Docker container.
*/
@GenerateDocumentation
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
void call(Map parameters = [:], body) {
handlePipelineStepErrors(stepName: STEP_NAME, stepParameters: parameters, failOnError: true) {
final script = checkScript(this, parameters) ?: this
def utils = parameters?.juStabUtils ?: new Utils()
Map config = ConfigurationHelper.newInstance(this)
.loadStepDefaults()
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
.mixinGeneralConfig(script.commonPipelineEnvironment, GENERAL_CONFIG_KEYS)
.mixinStepConfig(script.commonPipelineEnvironment, STEP_CONFIG_KEYS)
.mixinStageConfig(script.commonPipelineEnvironment, parameters.stageName?:env.STAGE_NAME, STEP_CONFIG_KEYS)
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
.mixin(parameters, PARAMETER_KEYS)
.use()
new Utils().pushToSWA([
step: STEP_NAME,
stepParamKey1: 'scriptMissing',
stepParam1: parameters?.script == null,
stepParamKey2: 'kubernetes',
stepParam2: isKubernetes()
], config)
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
if (isKubernetes() && config.dockerImage) {
List dockerEnvVars = []
config.dockerEnvVars?.each { key, value ->
dockerEnvVars << "$key=$value"
}
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
if (env.POD_NAME && isContainerDefined(config)) {
container(getContainerDefined(config)) {
withEnv(dockerEnvVars) {
echo "[INFO][${STEP_NAME}] Executing inside a Kubernetes Container."
body()
sh "chown -R 1000:1000 ."
}
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
}
} else {
if (!config.sidecarImage) {
dockerExecuteOnKubernetes(
script: script,
containerCommand: config.containerCommand,
containerShell: config.containerShell,
dockerImage: config.dockerImage,
dockerPullImage: config.dockerPullImage,
dockerEnvVars: config.dockerEnvVars,
dockerWorkspace: config.dockerWorkspace,
stashContent: config.stashContent
){
echo "[INFO][${STEP_NAME}] Executing inside a Kubernetes Pod"
body()
}
} else {
if(!config.dockerName){
config.dockerName = UUID.randomUUID().toString()
}
Map paramMap = [
script: script,
containerCommands: [:],
containerEnvVars: [:],
containerPullImageFlags: [:],
containerMap: [:],
containerName: config.dockerName,
containerPortMappings: [:],
containerWorkspaces: [:],
stashContent: config.stashContent
]
paramMap.containerCommands[config.sidecarImage] = ''
paramMap.containerEnvVars[config.dockerImage] = config.dockerEnvVars
paramMap.containerEnvVars[config.sidecarImage] = config.sidecarEnvVars
paramMap.containerPullImageFlags[config.dockerImage] = config.dockerPullImage
paramMap.containerPullImageFlags[config.sidecarImage] = config.sidecarPullImage
paramMap.containerMap[config.dockerImage] = config.dockerName
paramMap.containerMap[config.sidecarImage] = config.sidecarName
paramMap.containerPortMappings = config.containerPortMappings
paramMap.containerWorkspaces[config.dockerImage] = config.dockerWorkspace
paramMap.containerWorkspaces[config.sidecarImage] = ''
dockerExecuteOnKubernetes(paramMap){
echo "[INFO][${STEP_NAME}] Executing inside a Kubernetes Pod with sidecar container"
if(config.sidecarReadyCommand) {
waitForSidecarReadyOnKubernetes(config.sidecarName, config.sidecarReadyCommand)
}
body()
}
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
}
}
} else {
boolean executeInsideDocker = true
if (!JenkinsUtils.isPluginActive(PLUGIN_ID_DOCKER_WORKFLOW)) {
echo "[WARNING][${STEP_NAME}] Docker not supported. Plugin '${PLUGIN_ID_DOCKER_WORKFLOW}' is not installed or not active. Configured docker image '${config.dockerImage}' will not be used."
executeInsideDocker = false
}
returnCode = sh script: 'docker ps -q > /dev/null', returnStatus: true
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
if (returnCode != 0) {
echo "[WARNING][$STEP_NAME] Cannot connect to docker daemon (command 'docker ps' did not return with '0'). Configured docker image '${config.dockerImage}' will not be used."
executeInsideDocker = false
}
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
if (executeInsideDocker && config.dockerImage) {
utils.unstashAll(config.stashContent)
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
def image = docker.image(config.dockerImage)
if (config.dockerPullImage) image.pull()
else echo"[INFO][$STEP_NAME] Skipped pull of image '${config.dockerImage}'."
if (!config.sidecarImage) {
image.inside(getDockerOptions(config.dockerEnvVars, config.dockerVolumeBind, config.dockerOptions)) {
body()
}
} else {
def networkName = "sidecar-${UUID.randomUUID()}"
sh "docker network create ${networkName}"
try{
def sidecarImage = docker.image(config.sidecarImage)
if (config.sidecarPullImage) sidecarImage.pull()
else echo"[INFO][$STEP_NAME] Skipped pull of image '${config.sidecarImage}'."
config.sidecarOptions = config.sidecarOptions?:[]
if (config.sidecarName)
config.sidecarOptions.add("--network-alias ${config.sidecarName}")
config.sidecarOptions.add("--network ${networkName}")
sidecarImage.withRun(getDockerOptions(config.sidecarEnvVars, config.sidecarVolumeBind, config.sidecarOptions)) { container ->
config.dockerOptions = config.dockerOptions?:[]
if (config.dockerName)
config.dockerOptions.add("--network-alias ${config.dockerName}")
config.dockerOptions.add("--network ${networkName}")
if(config.sidecarReadyCommand) {
waitForSidecarReadyOnDocker(container.id, config.sidecarReadyCommand)
}
image.inside(getDockerOptions(config.dockerEnvVars, config.dockerVolumeBind, config.dockerOptions)) {
echo "[INFO][${STEP_NAME}] Running with sidecar container."
body()
}
}
}finally{
sh "docker network remove ${networkName}"
}
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
}
} else {
echo "[INFO][${STEP_NAME}] Running on local environment."
body()
}
}
}
}
private waitForSidecarReadyOnDocker(String containerId, String command){
String dockerCommand = "docker exec ${containerId} ${command}"
waitForSidecarReady(dockerCommand)
}
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
private waitForSidecarReadyOnKubernetes(String containerName, String command){
container(name: containerName){
waitForSidecarReady(command)
}
}
private waitForSidecarReady(String command){
int sleepTimeInSeconds = 10
int timeoutInSeconds = 5 * 60
int maxRetries = timeoutInSeconds / sleepTimeInSeconds
int retries = 0
while(true){
echo "Waiting for sidecar container"
String status = sh script:command, returnStatus:true
if(status == "0") return
if(retries > maxRetries){
error("Timeout while waiting for sidecar container to be ready")
}
sleep sleepTimeInSeconds
retries++
}
}
/*
* Returns a string with docker options containing
* environment variables (if set).
* Possible to extend with further options.
* @param dockerEnvVars Map with environment variables
*/
@NonCPS
private getDockerOptions(Map dockerEnvVars, Map dockerVolumeBind, def dockerOptions) {
def specialEnvironments = [
'http_proxy',
'https_proxy',
'no_proxy',
'HTTP_PROXY',
'HTTPS_PROXY',
'NO_PROXY'
]
def options = []
if (dockerEnvVars) {
for (String k : dockerEnvVars.keySet()) {
options.add("--env ${k}=${dockerEnvVars[k].toString()}")
}
}
for (String envVar : specialEnvironments) {
if (dockerEnvVars == null || !dockerEnvVars.containsKey(envVar)) {
options.add("--env ${envVar}")
}
}
if (dockerVolumeBind) {
for (String k : dockerVolumeBind.keySet()) {
options.add("--volume ${k}:${dockerVolumeBind[k].toString()}")
}
}
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
if (dockerOptions) {
if (dockerOptions instanceof CharSequence) {
dockerOptions = [dockerOptions]
}
if (dockerOptions instanceof List) {
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
for (String option : dockerOptions) {
options << escapeBlanks(option)
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
}
} else {
throw new IllegalArgumentException("Unexpected type for dockerOptions. Expected was either a list or a string. Actual type was: '${dockerOptions.getClass()}'")
}
}
return options.join(' ')
}
Enable support for executing on K8S as a step (#231) * Create executeDockerOnKubernetes.groovy * Update dockerExecute.groovy * Create SysEnvTest.groovy * Update default_pipeline_environment.yml * Update executeDockerOnKubernetes.groovy * Create utils object * update docker image * Update mavenExecute.groovy * Use pipeline-lib than piper * Check container name * Always change ownership to 1000 * Check for map * Fix command * Move chmod to docker execute * Use generic name for the pod * runAsPod has been added * Return false if script has no k8smapping * fix syntax error * Null checks * Returnn dockerImage name * Check method body * Return container name * Cleanup echos * Use runAsPod * Rename step * Use official jenkins JNLP agent image * Construct containersMap * Check if kubernetes plugin is active * Support JaaS * pass script object * Move configuration to default section * Use generic flag to check if running in k8s * fix jnlp agent name * Solve travis errors * Improvements to config and changes to name of the method * Improvements to config * Fix type * Rename stash config * add import * Fix map order * Fix jnlp agent name * cleanup config usage * Check if config is enabled * Use nested k8s mapping * Support custom docker workspace and move flag to env * Feature/k8s stage (#1) * Use nested k8s mapping * Support custom docker workspace and move flag to env * Check dockerOptions value * Support local execution * Add tests for dockerExecute * Move config to step and Fix tests * Use step configuration while running as a pod * Streamline parameter and config initialization * Streamline parameter and tests * Cleanup and align variable name * Use default JNLP agent if one not defined in config * Add tests for runInsidePod. Ensure lowercase container names. * Improve tests and remove unused code block * Fix permission issues * Perform stashing and unstashing inside container * Use custom jnlp agent due to user id restriction * Fix tests after jnlp agent change * Address review comments * Initialize script to default value if null * Address review comments * Update exeception handling and documentation * Improve documentation * correct indent * Link documents to the index page * Merge containerExecute and dockerExecuteOnKuberenetes step and address comments. * Update dockerExecute.md * Update dockerExecuteOnKubernetes.md * Update default_pipeline_environment.yml * update documentation * Update documentation. Use annotation for singleton * Update DockerExecuteOnKubernetesTest.groovy * Update dockerExecute.groovy * Update dockerExecuteOnKubernetes.groovy * Improve documentation and test case names * neoDeploy: switch to chained ConfigurationHelper (#244) * switch neoDeploy to chained ConfigurationHelper * update imports * Improve tests * Address review comments * Improve documentation * made dockerImage non-mandatory parm, improved test * add comment regarding userid assumption
2018-08-21 15:45:59 +02:00
boolean isContainerDefined(config) {
Map containerMap = ContainerMap.instance.getMap()
if (!containerMap.containsKey(env.POD_NAME)) {
return false
}
return containerMap.get(env.POD_NAME).containsKey(config.dockerImage)
}
def getContainerDefined(config) {
return ContainerMap.instance.getMap().get(env.POD_NAME).get(config.dockerImage).toLowerCase()
}
boolean isKubernetes() {
return Boolean.valueOf(env.ON_K8S)
}
/*
* Escapes blanks for values in key/value pairs
* E.g. <code>description=Lorem ipsum</code> is
* changed to <code>description=Lorem\ ipsum</code>.
*/
@NonCPS
def escapeBlanks(def s) {
def EQ='='
def parts=s.split(EQ)
if(parts.length == 2) {
parts[1]=parts[1].replaceAll(' ', '\\\\ ')
s = parts.join(EQ)
}
return s
}