Jenkins ver. 2.60.1 (running in container on kubernetes)
Kubernetes Plugin ver. 0.11 (https://github.com/jenkinsci/kubernetes-plugin)
Pipeline test:
podTemplate(
label: 'mypod',
volumes: [
persistentVolumeClaim(claimName: 'nfs-maven', mountPath: '/mnt/', readOnly: false)],
envVars: [
containerEnvVar(key: 'FOO', value: 'BAR'),
],
containers: [
containerTemplate(name: 'golang',
image: 'golang',
ttyEnabled: true,
command: 'cat',
)]
)
{
node('mypod') {
stage('test env') {
container('golang') {
stage('build') {
sh 'echo $FOO'
sh 'sleep 3600'
}
}
}
}
}
The vars are not passed into the containers. The echo echoes nothing. echo $FOO or echo \$FOO I have tried on the pod level and container level.
When i describe the created pod i only get the following environment vars:
Environment:
JENKINS_LOCATION_URL: http://ldn1-kube1:31000/
JENKINS_SECRET: 107cb696a8792f998fd41b6ccacf833ea74941fc9a95c39c4b2a1cde4c008b35
JENKINS_JNLP_URL: http://10.233.60.248:8080/computer/kubernetes-57beb710bfb44cea8f964d63049b2942-355760c790d6b/slave-agent.jnlp
JENKINS_TUNNEL: 10.233.60.248:50000
JENKINS_NAME: kubernetes-57beb710bfb44cea8f964d63049b2942-355760c790d6b
JENKINS_URL: http://10.233.60.248:8080
HOME: /home/jenkins
kubectl get -o yaml pod -l mypod
(I'd have to check the syntax for a label without a value, or of course you can get the pod's name) to see how the podTemplate is applying in real life? I also find it super,super,super suspicious none of the k8s service env-vars are present (KUBERNETES_SERVICE_HOST
,KUBERNETES_SERVICE_PORT
, etc) – mdaniel