0

I am trying a maven pipeline in jenkins on my windows machine. I am running the jenkins container through below command:

docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins

My Jenkinsfile is as follows:

pipeline {
    agent {
        docker {
            image 'maven:3.8.1-adoptopenjdk-11' 
            args '-v /root/.m2:/root/.m2' 
        }
    }
    stages {
        stage('Build') { 
            steps {
                sh 'mvn -B -DskipTests clean package' 
            }
        }
    }
}

while building the pipeline i am getting the below error:

+ docker inspect -f . maven:3.8.1-adoptopenjdk-11
/var/jenkins_home/workspace/simple-java-maven-app@tmp/durable-2227453d/script.sh: 1: 
/var/jenkins_home/workspace/simple-java-maven-app@tmp/durable-2227453d/script.sh: docker: not found
[Pipeline] isUnix
[Pipeline] sh
+ docker pull maven:3.8.1-adoptopenjdk-11
/var/jenkins_home/workspace/simple-java-maven-app@tmp/durable-f8b58578/script.sh: 1: 
/var/jenkins_home/workspace/simple-java-maven-app@tmp/durable-f8b58578/script.sh: docker: not found
[Pipeline] }

Docker desktop is already installed on my machine so not able to get Why I am getting "docker:not found" error.

Can anyone please point out if I am missing something.

Thanks,

Manish
  • 1,274
  • 3
  • 22
  • 59

1 Answers1

1

If you run the command such as :

docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins

you don't provide a way to jenkins to access to the docker installed on your host.
To allow that, mount the docker socket as a volume inside your docker run command.

On windows (according to Bind to docker socket on Windows) :

-v //var/run/docker.sock:/var/run/docker.sock

And on linux :

-v /var/run/docker.sock:/var/run/docker.sock 
davidxxx
  • 125,838
  • 23
  • 214
  • 215
  • it's not working even i followed the same – Manish May 29 '21 at 06:49
  • o/p of docker inspect as follows "Mounts":[{"Type":"volume","Name":"jenkinsVolume","Source":"/var/lib/docker/volumes/jenkinsVolume/_data","Destination":"/var/jenkins_home","Driver":"local","Mode":"z","RW":true,"Propagation":""},{"Type":"bind","Source":"//var/run/docker.sock","Destination":"/var/run/docker.sock","Mode":"","RW":true,"Propagation":"rprivate"}], – Manish May 29 '21 at 06:51