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?

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Best Answer

  • 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

    1. pipeline {
    2.  
    3. agent {
    4. kubernetes {
    5. yamlFile 'build-agent.yaml'
    6. defaultContainer 'alpine'
    7. idleMinutes 1
    8. }
    9. }
    10. stages {
    11. stage('Sample Stage') {
    12. parallel {
    13. stage('this runs in a pod') {
    14. steps {
    15. container('alpine') {
    16. sh 'uptime'
    17. }
    18. }
    19. }
    20. }
    21. }
    22. }
    23. }

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

    file : build-agent.yaml

    1. apiVersion: v1
    2. kind: Pod
    3. metadata:
    4. labels:
    5. app: xyz
    6. spec:
    7. containers:
    8. - name: alpine
    9. image: alpine
    10. command:
    11. - cat
    12. tty: true
    13.  

    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.

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Welcome!

It looks like you're new here. Sign in or register to get started.
Sign In

Categories

Upcoming Training