1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/DockerExecuteOnKubernetesTest.groovy

284 lines
10 KiB
Groovy
Raw Normal View History

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
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 org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
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 util.BasePiperTest
import util.JenkinsDockerExecuteRule
import util.JenkinsLoggingRule
import util.JenkinsReadYamlRule
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 util.JenkinsShellCallRule
import util.JenkinsStepRule
import util.PluginMock
import util.Rules
import static org.hamcrest.Matchers.*
import static org.junit.Assert.assertThat
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 static org.junit.Assert.assertTrue
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertFalse
class DockerExecuteOnKubernetesTest extends BasePiperTest {
private ExpectedException exception = ExpectedException.none()
private JenkinsDockerExecuteRule jder = new JenkinsDockerExecuteRule(this)
private JenkinsShellCallRule jscr = new JenkinsShellCallRule(this)
private JenkinsLoggingRule jlr = new JenkinsLoggingRule(this)
private JenkinsStepRule jsr = new JenkinsStepRule(this)
@Rule
public RuleChain ruleChain = Rules
.getCommonRules(this)
.around(new JenkinsReadYamlRule(this))
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
.around(exception)
.around(jder)
.around(jscr)
.around(jlr)
.around(jsr)
int whichDockerReturnValue = 0
def bodyExecuted
def dockerImage
def containerMap
def dockerEnvVars
def dockerWorkspace
def podName = ''
def podLabel = ''
def containersList = []
def imageList = []
def containerName = ''
def containerShell = ''
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 envList = []
def portList = []
def containerCommands = []
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
@Before
void init() {
containersList = []
imageList = []
envList = []
portList = []
containerCommands = []
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
bodyExecuted = false
JenkinsUtils.metaClass.static.isPluginActive = { def s -> new PluginMock(s).isActive() }
helper.registerAllowedMethod('sh', [Map.class], {return whichDockerReturnValue})
helper.registerAllowedMethod('container', [Map.class, Closure.class], { Map config, Closure body -> container(config){body()}
})
helper.registerAllowedMethod('podTemplate', [Map.class, Closure.class], { Map options, Closure body ->
podName = options.name
podLabel = options.label
options.containers.each { option ->
containersList.add(option.name)
imageList.add(option.image.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
envList.add(option.envVars)
portList.add(option.ports)
if (option.command) {
containerCommands.add(option.command)
}
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
}
body()
})
helper.registerAllowedMethod('node', [String.class, Closure.class], { String nodeName, Closure body -> body() })
helper.registerAllowedMethod('envVar', [Map.class], { Map option -> return option })
helper.registerAllowedMethod('containerTemplate', [Map.class], { Map option -> return option })
}
@Test
void testRunOnPodNoContainerMapOnlyDockerImage() throws Exception {
jsr.step.dockerExecuteOnKubernetes(
script: nullScript,
juStabUtils: utils,
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
dockerImage: 'maven:3.5-jdk-8-alpine',
dockerOptions: '-it',
dockerVolumeBind: ['my_vol': '/my_vol'],
dockerEnvVars: ['http_proxy': 'http://proxy:8000'], dockerWorkspace: '/home/piper'
){
bodyExecuted = 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
}
assertThat(containersList, hasItem('container-exec'))
assertThat(imageList, hasItem('maven:3.5-jdk-8-alpine'))
assertThat(envList.toString(), containsString('http_proxy'))
assertThat(envList.toString(), containsString('http://proxy:8000'))
assertThat(envList.toString(), containsString('/home/piper'))
assertThat(bodyExecuted, is(true))
assertThat(containerCommands.size(), is(1))
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
}
@Test
void testDockerExecuteOnKubernetesWithCustomContainerMap() throws Exception {
jsr.step.dockerExecuteOnKubernetes(script: nullScript,
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
containerMap: ['maven:3.5-jdk-8-alpine': 'mavenexecute']) {
container(name: 'mavenexecute') {
bodyExecuted = true
}
}
assertEquals('mavenexecute', containerName)
assertTrue(containersList.contains('mavenexecute'))
assertTrue(imageList.contains('maven:3.5-jdk-8-alpine'))
assertTrue(bodyExecuted)
assertThat(containerCommands.size(), is(1))
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
}
@Test
void testDockerExecuteOnKubernetesWithCustomJnlpWithContainerMap() throws Exception {
nullScript.commonPipelineEnvironment.configuration = ['general': ['jenkinsKubernetes': ['jnlpAgent': 'myJnalpAgent']]]
jsr.step.dockerExecuteOnKubernetes(script: nullScript,
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
containerMap: ['maven:3.5-jdk-8-alpine': 'mavenexecute']) {
container(name: 'mavenexecute') {
bodyExecuted = true
}
}
assertEquals('mavenexecute', containerName)
assertTrue(containersList.contains('mavenexecute'))
assertTrue(imageList.contains('maven:3.5-jdk-8-alpine'))
assertTrue(containersList.contains('jnlp'))
assertTrue(imageList.contains('myJnalpAgent'))
assertTrue(bodyExecuted)
}
@Test
void testDockerExecuteOnKubernetesWithCustomJnlpWithDockerImage() throws Exception {
nullScript.commonPipelineEnvironment.configuration = ['general': ['jenkinsKubernetes': ['jnlpAgent': 'myJnalpAgent']]]
jsr.step.dockerExecuteOnKubernetes(
script: nullScript,
juStabUtils: utils,
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
dockerImage: 'maven:3.5-jdk-8-alpine') {
bodyExecuted = true
}
assertEquals('container-exec', containerName)
assertTrue(containersList.contains('jnlp'))
assertTrue(containersList.contains('container-exec'))
assertTrue(imageList.contains('myJnalpAgent'))
assertTrue(imageList.contains('maven:3.5-jdk-8-alpine'))
assertTrue(bodyExecuted)
}
@Test
void testDockerExecuteOnKubernetesWithCustomWorkspace() throws Exception {
jsr.step.dockerExecuteOnKubernetes(script: nullScript,
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
containerMap: ['maven:3.5-jdk-8-alpine': 'mavenexecute'],
dockerWorkspace: '/home/piper') {
container(name: 'mavenexecute') {
bodyExecuted = true
}
}
assertTrue(envList.toString().contains('/home/piper'))
assertTrue(bodyExecuted)
}
@Test
void testDockerExecuteOnKubernetesWithCustomEnv() throws Exception {
jsr.step.dockerExecuteOnKubernetes(script: nullScript,
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
containerMap: ['maven:3.5-jdk-8-alpine': 'mavenexecute'],
dockerEnvVars: ['customEnvKey': 'customEnvValue']) {
container(name: 'mavenexecute') {
bodyExecuted = true
}
}
assertTrue(envList.toString().contains('customEnvKey') && envList.toString().contains('customEnvValue'))
assertTrue(bodyExecuted)
}
@Test
void testDockerExecuteOnKubernetesUpperCaseContainerName() throws Exception {
jsr.step.dockerExecuteOnKubernetes(script: nullScript,
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
containerMap: ['maven:3.5-jdk-8-alpine': 'MAVENEXECUTE'],
dockerEnvVars: ['customEnvKey': 'customEnvValue']) {
container(name: 'mavenexecute') {
bodyExecuted = true
}
}
assertEquals('mavenexecute', containerName)
assertTrue(containersList.contains('mavenexecute'))
assertTrue(imageList.contains('maven:3.5-jdk-8-alpine'))
assertTrue(bodyExecuted)
}
@Test
void testDockerExecuteOnKubernetesEmptyContainerMapNoDockerImage() throws Exception {
exception.expect(IllegalArgumentException.class);
jsr.step.dockerExecuteOnKubernetes(
script: nullScript,
juStabUtils: utils,
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
containerMap: [:],
dockerEnvVars: ['customEnvKey': 'customEnvValue']) {
container(name: 'jnlp') {
bodyExecuted = true
}
}
assertFalse(bodyExecuted)
}
@Test
void testSidecarDefault() {
List portMapping = []
helper.registerAllowedMethod('portMapping', [Map.class], {m ->
portMapping.add(m)
return m
})
jsr.step.dockerExecuteOnKubernetes(
script: nullScript,
juStabUtils: utils,
containerCommands: ['selenium/standalone-chrome': ''],
containerEnvVars: [
'selenium/standalone-chrome': ['customEnvKey': 'customEnvValue']
],
containerMap: [
'maven:3.5-jdk-8-alpine': 'mavenexecute',
'selenium/standalone-chrome': 'selenium'
],
containerName: 'mavenexecute',
containerPortMappings: [
'selenium/standalone-chrome': [[containerPort: 4444, hostPort: 4444]]
],
containerWorkspaces: [
'selenium/standalone-chrome': ''
],
dockerWorkspace: '/home/piper'
) {
bodyExecuted = true
}
assertThat(bodyExecuted, is(true))
assertThat(containerName, is('mavenexecute'))
assertThat(containersList, allOf(
hasItem('jnlp'),
hasItem('mavenexecute'),
hasItem('selenium'),
))
assertThat(imageList, allOf(
hasItem('s4sdk/jenkins-agent-k8s:latest'),
hasItem('maven:3.5-jdk-8-alpine'),
hasItem('selenium/standalone-chrome'),
))
assertThat(portList, hasItem(hasItem([name: 'selenium0', containerPort: 4444, hostPort: 4444])))
assertThat(portMapping, hasItem([name: 'selenium0', containerPort: 4444, hostPort: 4444]))
assertThat(containerCommands.size(), is(1))
assertThat(envList, hasItem(hasItem(allOf(hasEntry('key', 'customEnvKey'), hasEntry ('value','customEnvValue')))))
}
@Test
void testDockerExecuteOnKubernetesWithCustomShell() {
jsr.step.dockerExecuteOnKubernetes(
script: nullScript,
juStabUtils: utils,
dockerImage: 'maven:3.5-jdk-8-alpine',
containerShell: '/busybox/sh'
) {
//nothing to exeute
}
assertThat(containerShell, is('/busybox/sh'))
}
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 container(options, body) {
containerName = options.name
containerShell = options.shell
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
body()
}
}