-
Bug
-
Resolution: Unresolved
-
Major
-
None
It seems I cannot define a default jnlp container to be used for all the pods and the plugin defaults always to "jenkins/inbound-agent:4.3-4".
I specified a custom image in the kubernetes configure clouds page, but the template has always no container and not even the custom ENV var that I specify.
The workaround I found, is to specify the jnlp in the yaml variable, but i'd prefer to have a global one.
Here the code:
node("worker") { String yaml = """ kind: Pod apiVersion: v1 spec: containers: - name: bash image: registry.example.com/registry/shell:bash5.0-alpine3.12 imagePullPolicy: Always command: ["cat"] tty: true """ podTemplate(yaml: yaml) { node(POD_LABEL) { stage("Build for packaging") { container('bash') { sh label: "Build for packaging", script: """ set -e echo "Test" """ } } } } }
Here the logs:
Jun 17, 2021 6:13:07 PM FINEST org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils Parsed pod template from yaml: --- apiVersion: "v1" kind: "Pod" spec: containers: - command: - "cat" image: "registry.example.com/registry/shell:bash5.0-alpine3.12" imagePullPolicy: "Always" name: "bash" tty: trueJun 17, 2021 6:13:13 PM FINE org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud In provisioning : [] Jun 17, 2021 6:13:13 PM FINE org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud Label "TestC_10-c7j6c" excess workload: 1, executors: 0 Jun 17, 2021 6:13:13 PM FINE org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud Template for label "TestC_10-c7j6c": TestC_10-c7j6c-rg2vb Jun 17, 2021 6:13:13 PM FINEST org.csanchez.jenkins.plugins.kubernetes.KubernetesProvisioningLimits kubernetes global limit: 1/10 Jun 17, 2021 6:13:13 PM FINEST org.csanchez.jenkins.plugins.kubernetes.KubernetesProvisioningLimits TestC_10-c7j6c-rg2vb template limit: 1/2147483647 Jun 17, 2021 6:13:13 PM FINEST org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud Planned 1 Kubernetes agents with template "TestC_10-c7j6c-rg2vb" Jun 17, 2021 6:13:14 PM FINEST org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud Building connection to Kubernetes kubernetes URL https://kubernetes.default namespace jenkins Jun 17, 2021 6:13:14 PM FINE org.csanchez.jenkins.plugins.kubernetes.KubernetesFactoryAdapter Creating Kubernetes client: KubernetesFactoryAdapter [serviceAddress=https://kubernetes.default, namespace=jenkins, caCertData=null, credentials=null, skipTlsVerify=false, connectTimeout=5, readTimeout=15] Jun 17, 2021 6:13:14 PM FINE org.csanchez.jenkins.plugins.kubernetes.KubernetesFactoryAdapter Proxy Settings for Cloud: false Jun 17, 2021 6:13:14 PM FINE org.csanchez.jenkins.plugins.kubernetes.KubernetesClientProvider Created new Kubernetes client: kubernetes io.fabric8.kubernetes.client.DefaultKubernetesClient@65831bf Jun 17, 2021 6:13:14 PM FINE org.csanchez.jenkins.plugins.kubernetes.KubernetesCloud Connected to Kubernetes kubernetes URL https://kubernetes.default/ namespace jenkins Jun 17, 2021 6:13:14 PM FINEST org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils Parsed pod template from yaml: --- apiVersion: "v1" kind: "Pod" spec: containers: - command: - "cat" image: "registry.example.com/registry/shell:bash5.0-alpine3.12" imagePullPolicy: "Always" name: "bash" tty: trueJun 17, 2021 6:13:14 PM FINEST org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils Combining pods, parent: --- apiVersion: "v1" kind: "Pod" metadata: {} spec: containers: - command: - "cat" image: "registry.example.com/registry/shell:bash5.0-alpine3.12" imagePullPolicy: "Always" name: "bash" tty: true template: --- apiVersion: "v1" kind: "Pod" metadata: annotations: buildUrl: "http://jenkins.jenkins.svc.cluster.local:8080/job/TestC/10/" runUrl: "job/TestC/10/" labels: jenkins/jenkins-jenkins-agent: "true" jenkins/label-digest: "5eee0bc5e5793f888965251dee9e803c7e074684" jenkins/label: "TestC_10-c7j6c" name: "testc-10-c7j6c-rg2vb-jllp6" spec: containers: [] volumes: - emptyDir: medium: "" name: "workspace-volume"Jun 17, 2021 6:13:14 PM FINEST org.csanchez.jenkins.plugins.kubernetes.PodTemplateUtils Pods combined: --- apiVersion: "v1" kind: "Pod" metadata: annotations: buildUrl: "http://jenkins.jenkins.svc.cluster.local:8080/job/TestC/10/" runUrl: "job/TestC/10/" labels: jenkins/jenkins-jenkins-agent: "true" jenkins/label-digest: "5eee0bc5e5793f888965251dee9e803c7e074684" jenkins/label: "TestC_10-c7j6c" name: "testc-10-c7j6c-rg2vb-jllp6" spec: containers: - command: - "cat" image: "registry.example.com/registry/shell:bash5.0-alpine3.12" imagePullPolicy: "Always" name: "bash" tty: true nodeSelector: {} volumes: - emptyDir: medium: "" name: "workspace-volume"Jun 17, 2021 6:13:14 PM FINEST org.csanchez.jenkins.plugins.kubernetes.PodTemplateBuilder Pod built: --- apiVersion: "v1" kind: "Pod" metadata: annotations: buildUrl: "http://jenkins.jenkins.svc.cluster.local:8080/job/TestC/10/" runUrl: "job/TestC/10/" labels: jenkins/jenkins-jenkins-agent: "true" jenkins/label-digest: "5eee0bc5e5793f888965251dee9e803c7e074684" jenkins/label: "TestC_10-c7j6c" name: "testc-10-c7j6c-rg2vb-jllp6" spec: containers: - command: - "cat" image: "registry.example.com/registry/shell:bash5.0-alpine3.12" imagePullPolicy: "Always" name: "bash" tty: true volumeMounts: - mountPath: "/home/jenkins/agent" name: "workspace-volume" readOnly: false - env: - name: "JENKINS_SECRET" value: "b1ac3255b8ae76de67e1723b23c9ac68d81cb6ed388cc4ea13d5c17ccc08bf33" - name: "JENKINS_TUNNEL" value: "jenkins-agent.jenkins.svc.cluster.local:50000" - name: "JENKINS_AGENT_NAME" value: "testc-10-c7j6c-rg2vb-jllp6" - name: "JENKINS_NAME" value: "testc-10-c7j6c-rg2vb-jllp6" - name: "JENKINS_AGENT_WORKDIR" value: "/home/jenkins/agent" - name: "JENKINS_URL" value: "http://jenkins.jenkins.svc.cluster.local:8080/" image: "jenkins/inbound-agent:4.3-4" name: "jnlp" resources: limits: {} requests: memory: "256Mi" cpu: "100m" volumeMounts: - mountPath: "/home/jenkins/agent" name: "workspace-volume" readOnly: false nodeSelector: kubernetes.io/os: "linux" restartPolicy: "Never" volumes: - emptyDir: medium: "" name: "workspace-volume"
Solved. The way (maybe not super clear in the documentation) is to set a default provider template name (Configure clouds page -> Kubernetes -> Click on Kubernetes Cloud details ... -> Click on Advanced -> Default Provider Template Name).
And also use the same name in the Pod Template -> name field.
Then set the desired jnlp container template image.
Check this log snippet, where the template uses the custom "registry.example.com/registry/custom-jnlp:123" image.