mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
c84114c3df
* 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
2.9 KiB
2.9 KiB
dockerExecuteOnKubernetes
Description
Executes a closure inside a container in a kubernetes pod. Proxy environment variables defined on the Jenkins machine are also available in the container.
Prerequisites
- The Jenkins should be running on kubernetes.
- An environment variable
ON_K8S
should be created on Jenkins and initialized totrue
.
Parameters
parameter | mandatory | default | possible values |
---|---|---|---|
script |
no | empty globalPipelineEnvironment |
|
dockerImage |
yes | ||
dockerEnvVars |
no | [:] | |
dockerWorkspace |
no | '' | |
containerMap |
no | [:] |
script
defines the global script environment of the Jenkins file run. Typicallythis
is passed to this parameter. This allows the function to access thecommonPipelineEnvironment
for storing the measured duration.dockerImage
Name of the docker image that should be used. If empty, Docker is not used.dockerEnvVars
Environment variables to set in the container, e.g. [http_proxy:'proxy:8080']dockerWorkspace
Docker options to be set when starting the container. It can be a list or a string.containerMap
A map of docker image to the name of the container. The pod will be created with all the images from this map and they are labled based on the value field of each map entry. Ex['maven:3.5-jdk-8-alpine': 'mavenExecute', 'famiko/jmeter-base': 'checkJMeter', 's4sdk/docker-cf-cli': 'cloudfoundry']
Step configuration
none
Return value
none
Side effects
none
Exceptions
none
Example 1: Run a closure in a single container pod
# set environment variable
export ON_K8S=true"
dockerExecuteOnKubernetes(script: script, dockerImage: 'maven:3.5-jdk-7'){
sh "mvn clean install"
}
In the above example, a pod will be created with a docker container of image maven:3.5-jdk-7
. The closure will be then executed inside the container.
Example 2: Run a closure in a multi-container pod
# set environment variable
export ON_K8S=true"
dockerExecuteOnKubernetes(script: script, containerMap: ['maven:3.5-jdk-8-alpine': 'maven', 's4sdk/docker-cf-cli': 'cfcli']){
container('maven'){
sh "mvn clean install"
}
container('cfcli'){
sh "cf plugins"
}
}
In the above example, a pod will be created with multiple Docker containers that are passed as a containerMap
. The containers can be chosen for executing by referring their labels as shown in the example.