Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins : Cannot run program "docker": error=2, No such file or directory

I have installed Jenkins on my local machine which runs on MacOS High Sierra and have docker installed . I am trying to run a simple pipeline example which uses docker. I have added the following lines to pipeline :

pipeline {
    agent {
        docker { image 'node:7-alpine' }
    }
    stages {
        stage('Test') {
            steps {
                sh 'node --version'
            }
        }
    }
}

Then from the WebGUI, I click on build now and it is failing. Console output showing the error as follows :

java.io.IOException: error=2, No such file or directory
 at java.lang.UNIXProcess.forkAndExec(Native Method)
 at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
 at java.lang.ProcessImpl.start(ProcessImpl.java:134)
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
 at hudson.Proc$LocalProc.<init>(Proc.java:249)
 at hudson.Proc$LocalProc.<init>(Proc.java:218)
 at hudson.Launcher$LocalLauncher.launch(Launcher.java:929)
 at hudson.Launcher$ProcStarter.start(Launcher.java:449)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:296)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:277)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:274)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.version(DockerClient.java:246)
 at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:141)
 at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:229)
 at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153)
 at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
 at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
Caused: java.io.IOException: Cannot run program "docker": error=2, No such file or directory
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
 at hudson.Proc$LocalProc.<init>(Proc.java:249)
 at hudson.Proc$LocalProc.<init>(Proc.java:218)
 at hudson.Launcher$LocalLauncher.launch(Launcher.java:929)
 at hudson.Launcher$ProcStarter.start(Launcher.java:449)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:296)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:277)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.launch(DockerClient.java:274)
 at org.jenkinsci.plugins.docker.workflow.client.DockerClient.version(DockerClient.java:246)
 at org.jenkinsci.plugins.docker.workflow.WithContainerStep$Execution.start(WithContainerStep.java:141)
 at org.jenkinsci.plugins.workflow.cps.DSL.invokeStep(DSL.java:229)
 at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:153)
 at org.jenkinsci.plugins.workflow.cps.CpsScript.invokeMethod(CpsScript.java:122)
 at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:48)
 at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
 at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
 at com.cloudbees.groovy.cps.sandbox.DefaultInvoker.methodCall(DefaultInvoker.java:20)
 at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/Users/coder/.jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:135)
 at org.jenkinsci.plugins.docker.workflow.Docker.node(jar:file:/Users/coder/.jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:66)
 at org.jenkinsci.plugins.docker.workflow.Docker$Image.inside(jar:file:/Users/coder/.jenkins/plugins/docker-workflow/WEB-INF/lib/docker-workflow.jar!/org/jenkinsci/plugins/docker/workflow/Docker.groovy:123)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.DockerPipelineScript.runImage(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/DockerPipelineScript.groovy:57)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.AbstractDockerPipelineScript.configureRegistry(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/AbstractDockerPipelineScript.groovy:74)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.AbstractDockerPipelineScript.run(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/AbstractDockerPipelineScript.groovy:52)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.checkoutAndRun(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-extensions/WEB-INF/lib/pipeline-model-extensions.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy:66)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.CheckoutScript.doCheckout(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-extensions/WEB-INF/lib/pipeline-model-extensions.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/CheckoutScript.groovy:42)
 at org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.LabelScript.run(jar:file:/Users/coder/.jenkins/plugins/pipeline-model-definition/WEB-INF/lib/pipeline-model-definition.jar!/org/jenkinsci/plugins/pipeline/modeldefinition/agent/impl/LabelScript.groovy:44)
 at ___cps.transform___(Native Method)
 at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:57)
 at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
 at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:82)
 at sun.reflect.GeneratedMethodAccessor192.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:498)
 at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
 at com.cloudbees.groovy.cps.impl.ClosureBlock.eval(ClosureBlock.java:46)
 at com.cloudbees.groovy.cps.Next.step(Next.java:83)
 at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
 at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
 at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
 at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
 at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
 at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$101(SandboxContinuable.java:34)
 at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
 at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
 at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
 at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
 at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
 at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
 at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
 at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
 at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:131)
 at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
 at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
 at java.util.concurrent.FutureTask.run(FutureTask.java:266)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE

Why this is happening ? In the Jenkins documentation, they are only given this syntax and doesn't mentioned about anything else.

like image 943
Happy Coder Avatar asked May 14 '18 14:05

Happy Coder


3 Answers

I enncounter the same problem on macOS recently. It is solved by adding following lines to /usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.plist

    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>

It also need restart jenkins brew services restart jenkins-lts.

By the way, add PATH environment in jenkins web GUI don't fix the problem. It work in some part and failed the whole process which make it more confused and mislead me too much.

like image 86
Ren Weibo Avatar answered Oct 16 '22 12:10

Ren Weibo


I hit the same problem as above. I am not sure that my case is exactly the same as your but the TL;DR is that you need make sure that Docker is available to the PATH variable Jenkins is using. Specifically the one it starts up with, which can be seen under Jenkins Home -> Manage Jenkins -> System Information.

In my case, I am on a Mac and installed Jenkins through Homebrew. To fix the issue I edited the /usr/local/opt/jenkins-lts/homebrew.mxcl.jenkins-lts.plist file and changed it to the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>homebrew.mxcl.jenkins-lts</string>
    <key>ProgramArguments</key>
    <array>
      <string>/usr/libexec/java_home</string>
      <string>-v</string>
      <string>1.8</string>
      <string>--exec</string>
      <string>java</string>
      <string>-Dmail.smtp.starttls.enable=true</string>
      <string>-jar</string>
      <string>/usr/local/opt/jenkins-lts/libexec/jenkins.war</string>
      <string>--httpListenAddress=127.0.0.1</string>
      <string>--httpPort=8080</string>
    </array>
    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

The important part here is:

    <key>EnvironmentVariables</key>
    <dict>
      <key>PATH</key>
      <string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
    </dict>

in my case, docker is available at /usr/local/bin.

like image 44
James McMahon Avatar answered Oct 16 '22 13:10

James McMahon


I ran into some serious trouble with this too so I wanted to post my solution since I have not seen it around anywhere.

My setup was: A Mac Mini running Mac OS Sierra with jenkins and docker both installed locally. Jenkins could not call docker in groovy scripts, but the shell had access to docker commands.

Solution:

  1. Manage Jenkins > Global Tool Configuration
  2. Click to add a docker installation
  3. Name it whatever you wish, you will be using this name to identify the installation in the Groovy scripts
  4. Set the installation root to the installation location of your Docker (mine was in /usr/local by default). This did not work for me if I appended /bin this path as the docker plugin I was using in Jenkins does this automatically. We snooped around the source for docker-workflow-plugin to verify this ourselves.
  5. Save these changes
  6. Open your Groovy script where you want to call your docker installation and surround your docker calls in a block statement like this:

    docker.withTool('') { //whatever docker commands you wish to run here }

like image 5
Jojo Avatar answered Oct 16 '22 12:10

Jojo