mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-01-18 05:18:24 +02:00
Pass configured env vars to docker execution in existing container (#851)
This commit is contained in:
parent
fa3b6b68db
commit
f69eac6f5f
@ -48,10 +48,15 @@ class DockerExecuteTest extends BasePiperTest {
|
||||
|
||||
@Test
|
||||
void testExecuteInsideContainerOfExistingPod() throws Exception {
|
||||
List usedDockerEnvVars
|
||||
helper.registerAllowedMethod('container', [String.class, Closure.class], { String container, Closure body ->
|
||||
containerName = container
|
||||
body()
|
||||
})
|
||||
helper.registerAllowedMethod('withEnv',[List.class, Closure.class], { List envVars, Closure body ->
|
||||
usedDockerEnvVars = envVars
|
||||
body()
|
||||
})
|
||||
binding.setVariable('env', [POD_NAME: 'testpod', ON_K8S: 'true'])
|
||||
ContainerMap.instance.setMap(['testpod': ['maven:3.5-jdk-8-alpine': 'mavenexec']])
|
||||
stepRule.step.dockerExecute(script: nullScript,
|
||||
@ -61,6 +66,7 @@ class DockerExecuteTest extends BasePiperTest {
|
||||
}
|
||||
assertTrue(loggingRule.log.contains('Executing inside a Kubernetes Container'))
|
||||
assertEquals('mavenexec', containerName)
|
||||
assertEquals(usedDockerEnvVars[0].toString(), "http_proxy=http://proxy:8000")
|
||||
assertTrue(bodyExecuted)
|
||||
}
|
||||
|
||||
|
@ -133,12 +133,18 @@ void call(Map parameters = [:], body) {
|
||||
], config)
|
||||
|
||||
if (isKubernetes() && config.dockerImage) {
|
||||
List dockerEnvVars = []
|
||||
config.dockerEnvVars?.each { key, value ->
|
||||
dockerEnvVars << "$key=$value"
|
||||
}
|
||||
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 ."
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (!config.sidecarImage) {
|
||||
dockerExecuteOnKubernetes(
|
||||
|
Loading…
x
Reference in New Issue
Block a user