Welcome to the Linux Foundation Forum!

¿How to configure an Agent jenkins/inbound-agent with docker installed?

To follow the course, I installed my jenkins with HELM in k8s.
I am struggling to set up an Agent with docker installed.
I want to set up this one https://github.com/jenkinsci/jnlp-agents/tree/master/docker
https://hub.docker.com/r/jenkins/jnlp-agent-docker

Anyone can help me to substitute jenkins/inbound-agent:4.11-1 for jenkins/jnlp-agent-docker so I can have docker in the Agent?

Best Answer

  • gouravshah
    gouravshah Posts: 139
    Answer ✓

    @Miguel_Angel have you considered using kubernetes agent which launches a pod (with jnlp embedded into it as a container in addition to actual job container).

    Here is a sample Jenkinsfile (created from my existing pipeline, not tested)

    FIle: Jenkinsfile

    pipeline {
    
      agent {
        kubernetes {
          yamlFile 'build-agent.yaml'
          defaultContainer 'alpine'
          idleMinutes 1
        }
      }
      stages {
        stage('Sample Stage') {
          parallel {
            stage('this runs in a pod') {
              steps {
                container('alpine') {
                  sh 'uptime'
                }
              }
            }
          }
        }
        }
    }
    

    If you use configure above you would also have to add build agent config in its own file. For example,

    file : build-agent.yaml

    apiVersion: v1
    kind: Pod
    metadata:
      labels:
        app: xyz
    spec:
      containers:
        - name: alpine
          image: alpine
          command:
            - cat
          tty: true
    
    

    Let me know if this could help.

Answers

  • more info.

    I created this pipeline
    pipeline {
    agent { label 'docker' }
    stages {
    stage('Run docker') {
    steps {
    sh 'docker version'
    }
    }
    }
    }

    I added this agent
    The agent

    pods get error
    ❯ k get po -n jenkins -w
    NAME READY STATUS RESTARTS AGE
    docker-5w0j0 1/2 Terminating 0 2s
    jenkins-0 2/2 Running 0 35m
    docker-5w0j0 0/2 Terminating 0 3s
    docker-bqp3z 0/2 Pending 0 0s
    docker-bqp3z 0/2 Pending 0 0s
    docker-bqp3z 0/2 ContainerCreating 0 0s
    docker-bqp3z 1/2 Error 0 1s
    docker-bqp3z 1/2 Terminating 0 1s
    docker-5w0j0 0/2 Terminating 0 11s
    docker-5w0j0 0/2 Terminating 0 11s
    docker-bqp3z 0/2 Terminating 0 3s
    docker-87ss1 0/2 Pending 0 0s
    docker-87ss1 0/2 Pending 0 0s
    docker-87ss1 0/2 ContainerCreating 0 0s
    docker-87ss1 1/2 Error 0 1s
    docker-87ss1 1/2 Terminating 0 1s

  • Thanks @gouravshah
    It was so easy to implement.
    It works great and clean and net solution

  • cool ! Thanks for the feedback @Miguel_Angel. Glad it helped.

Categories

Upcoming Training