0

I'm new in Jenkins and learning it right now. I read that modern way to use Jenkins is to use docker containers as agents so:

  1. I created jenkins image with docker installed
FROM jenkins/jenkins:lts

USER root
RUN apt-get update -qq && \
    apt-get install -qqy apt-transport-https ca-certificates curl gnupg2 software-properties-common && \
    curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \
    apt-key fingerprint 0EBFCD88 && \
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && \
    apt-get update -qq && \
    apt-get install -qqy docker-ce && \
    usermod -aG docker jenkins && \
    chown -R jenkins:jenkins $JENKINS_HOME/

USER jenkins
  1. Created docker-compose (instend running docker run command all the time)
version: '3.8'
services:
  jenkins:
    image: tmateusz/jenkins:lts
    privileged: true
    user: root
    ports:
      - 8080:8080
      - 50000:50000
    container_name: jenkins
    volumes:
      - /MY_PATH/jenkins_configuration:/var/jenkins_home
      - /var/run/docker.sock:/var/run/docker.sock
    networks:
      - jenkins
networks:
  jenkins:
    name: jenkins_network
  1. Installed Docker Pipeline plugin in Jenkins Controller
  2. Created really simple pipeline to check it works:
pipeline {
    agent {
        docker {
            image 'eclipse-temurin:11'
        }
    }

    stages {
        stage('Check versions') {
            steps {
                sh 'java --version'
            }
        }
    }
}

And it fails. Checked again:

  1. When I exec jenkins container (docker exec -it jenkins bash) - "docker ps" works (so docker is installed in Jenkins controller container)

  2. When I run job - new container is created (with given image - image 'eclipse-temurin:11'

  3. When i exec into this new agent container - java --version return expected results.

  4. My job run and run (infinity - didnt wait more than 10 min)

  5. Logs:

Jenkins does not seem to be running inside a container
$ docker run -t -d -u 0:0 -w /var/jenkins_home/workspace/test-1.1 -v /var/jenkins_home/workspace/test-1.1:/var/jenkins_home/workspace/test-1.1:rw,z -v /var/jenkins_home/workspace/test-1.1@tmp:/var/jenkins_home/workspace/test-1.1@tmp:rw,z -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** -e ******** eclipse-temurin:11 cat
$ docker top 6d738c52e04050b008d07e19ef4d917ae3350771e2e12d62db780c97879a25f7 -eo pid,comm
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Check versions)
[Pipeline] sh
Sending interrupt signal to process
Aborted by admin
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
$ docker stop --time=1 6d738c52e04050b008d07e19ef4d917ae3350771e2e12d62db780c97879a25f7
$ docker rm -f 6d738c52e04050b008d07e19ef4d917ae3350771e2e12d62db780c97879a25f7
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
  1. It crash on running first Stage - I think that Jenkins agent container cant run pipeline commands.

How to do this? Is there something wrong with my Jenkins configuration?

Btw. working on linux

TMateusz
  • 1
  • 1

0 Answers0