4

Installed Jenkins using helm

helm install --name jenkins -f values.yaml stable/jenkins

Jenkins Plugin Installed

- kubernetes:1.12.6
- workflow-job:2.31
- workflow-aggregator:2.5
- credentials-binding:1.16
- git:3.9.3
- docker:1.1.6

Defined Jenkins pipeline to build docker container

node {
    checkout scm

    def customImage = docker.build("my-image:${env.BUILD_ID}")

    customImage.inside {
        sh 'make test'
    }
}

Throws the error : docker not found

enter image description here

2 Answers 2

2

You can define agent pod with containers with required tools(docker, Maven, Helm etc) in the pipeline for that:

First, create agentpod.yaml with following values:

apiVersion: v1

kind: Pod

metadata:

  labels:

    some-label: pod

spec:

  containers:

    - name: maven

      image: maven:3.3.9-jdk-8-alpine

      command:

        - cat

      tty: true

      volumeMounts:

        - name: m2

          mountPath: /root/.m2

    - name: docker

      image: docker:19.03

      command:

        - cat

      tty: true

      privileged: true

      volumeMounts:

        - name: dockersock

          mountPath: /var/run/docker.sock

  volumes:

    - name: dockersock

      hostPath:

        path: /var/run/docker.sock

    - name: m2

      hostPath:

        path: /root/.m2

Then configure the pipeline as:

pipeline {
    agent {
        kubernetes {
            defaultContainer 'jnlp'
            yamlFile 'agentpod.yaml'
        }
    }
    stages {
        stage('Build') {
            steps {
                container('maven') {
                    sh 'mvn package'
                }
            }
        }
        stage('Docker Build') {
            steps {
                container('docker') {
                    sh "docker build -t dockerimage ."
                }
            }
        }
    }
}
1

It seems like you have only installed plugins but not packages. Two possibilities.

  1. Configure plugins to install packages using Jenkins.

    • Go to Manage Jenkins
    • Global Tools Configuration
    • Docker -> Fill name (eg: Docker-latest)
    • Check on install automatically and then add installer (Download from here).enter image description here

    • Then save

  2. If you have installed on your machine then update the PATH variable in Jenkins with the location of Docker.

1
  • Are you still facing issue? if yes, can you please provide your values.yaml file? As Jenkins is running in pod kubernetes (container) and your are trying to create docker image which we generally do on host machine by mounting docker.sock file like -> /var/run/docker.sock:/var/run/docker.sock. but still Docker client needs to be installed on Jenkins container. Apr 16, 2019 at 2:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.