Configure Kubernetes plugin Jenkins with custom agent image

3/10/2020

I'm trying to configure kubernetes plugin in Jenkins with a custom image but when I launch the pipeline I get this error:

Started by user unknown or anonymous
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Still waiting to schedule task
‘testjenkinsslaveagent-54-blfkj-1zp9j-lbn6q’ is offline

where testjenkinsslaveagent is my pipeline name. Kubernetes plugin is configured as bellow: enter image description here and the pipeline si defined like this:

podTemplate(containers: [
        containerTemplate(name: 'jnlp', image: 'registry.gitlab.com/xxxx/dockerimages:latest', ttyEnabled: true, command: '/bin/sh'),
],volumes: [hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock')]) {

    node(POD_LABEL) {
        stage('Run') {
            container('my-slave') {
                sh 'echo hello world'
                sh 'ifconfig'
                sh 'sudo docker images ls'
            }
        }

    }
}

Jenkins version is 2.176.3 with all plugins updated.

Since I needed docker inside my agent I modifyed an existing Dockerimage like this (it works localy):

ARG version=4.0.1-1
FROM jenkins/slave:$version

ARG version
MAINTAINER Oleg Nenashev <o.v.nenashev@gmail.com>
LABEL Description="This is a base image, which allows connecting Jenkins agents via JNLP protocols" Vendor="Jenkins project" Version="$version"

ARG user=jenkins

USER root

COPY jenkins-agent /usr/local/bin/jenkins-agent
RUN chmod +x /usr/local/bin/jenkins-agent &&\
    ln -s /usr/local/bin/jenkins-agent /usr/local/bin/jenkins-slave


# Install docker routine
RUN echo 'Installing docker routine ...'
RUN apt-get update && \
    apt-get -y install apt-transport-https \
    ca-certificates \
    curl \
    gnupg2 \
    software-properties-common && \
    curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && \
    add-apt-repository \
    "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
    $(lsb_release -cs) \
    stable" && \
    apt-get update && \
    apt-get -y install docker-ce
RUN usermod -a -G docker jenkins
RUN mkdir -p /home/jenkins/.ssh && \
    chown -R 1000:1000 /home/jenkins/.ssh

USER ${user}

ENTRYPOINT ["jenkins-agent"]

The problem is that my custom agent docker image is ignored and Kubertete's plugin default image is instanciate. Any idea or any working tutorial on how to set up correctly these? Thank

-- Ares91
docker
jenkins
jenkins-pipeline
kubernetes
kubernetes-pod

0 Answers