Jenkins Agent 无法 运行 程序 "docker": error=2, No such file or directory
Jenkins Agent Cannot run program "docker": error=2, No such file or directory
我的詹金斯代理有一个奇怪的行为。我有一个主控和一个单独的构建代理,可以访问 docker.
而我 运行 构建代理上的以下管道脚本:
node {
sh "id"
sh "echo $PATH"
sh "docker ps"
docker.image("node:latest").inside("") {
sh "npm --version"
}
}
我得到以下输出:
Running on docker-agent in /home/jenkins/workspace/test
[Pipeline] {
[Pipeline] sh
[test] Running shell script
+ id
uid=1000(jenkins) gid=1000(jenkins) groups=900(docker),1000(jenkins),1000(jenkins)
[Pipeline] sh
[test] Running shell script
+ echo /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[Pipeline] sh
[test] Running shell script
+ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[Pipeline] sh
[test] Running shell script
+ docker inspect -f . node:latest
.
[Pipeline] withDockerContainer
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
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)
Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to docker-agent
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1741)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
at hudson.remoting.Channel.call(Channel.java:955)
at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1058)
at hudson.Launcher$ProcStarter.start(Launcher.java:454)
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:270)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:180)
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 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.GeneratedMethodAccessor94.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.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable.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.CpsThread.runNextChunk(CpsThread.java:174)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access0(CpsThreadGroup.java:83)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.call(CpsThreadGroup.java:244)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.call(CpsThreadGroup.java:232)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService.run(ImpersonatingExecutorService.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
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:935)
at hudson.Launcher$ProcStarter.start(Launcher.java:454)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1312)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1265)
at hudson.remoting.UserRequest.perform(UserRequest.java:212)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request.run(Request.java:369)
at hudson.remoting.InterceptingExecutorService.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
输出显示,docker ps 工作正常,当我 运行 它作为 shell。当我 运行 使用 docker 构建步骤时,它会导致给定的异常。
知道我做错了什么吗?
您是否已经像他们在 https://jenkins.io/doc/book/pipeline/docker/ 中所说的那样尝试过?
你需要 c -> 如:
node {
sh "id"
sh "echo $PATH"
sh "docker ps"
docker.image("node:latest").inside("") { c ->
sh "npm --version"
}
}
另一个例子:https://github.com/jenkinsci/pipeline-examples/pull/83/files
问题解决了。它有两个问题。
首先,我为构建代理设置了 PATH,它与 shell 命令一起工作正常,但管道无法与它一起工作。虽然 docker 位于 /usr/local/bin,但管道找不到它。它只知道 /usr/bin:/usr/sbin.
其次,我删除了 jenkins 构建代理配置中的 PATH 环境变量,并在 /usr/bin 中为 docker 创建了一个符号 link。
现在我的管道工作了。
Docker 插件从 java 启动 docker 并且不使用设置中的环境变量。我解决了将 PATH 添加到 jenkins-lts.plist
并重新启动 Jenkins
的问题
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
我终于通过在Prefix Start Agent Command
中添加export PATH="$PATH:/usr/local/bin";
解决了这个问题。
打开 管理 Jenkins -> 管理节点和云 -> -> 配置 - > 点击 Launch method
下的 高级 -> 添加 export PATH="$PATH:/usr/local/bin";
到 Prefix Start Agent Command
。
然后重新启动 Jenkins,它应该可以正常工作。
我的詹金斯代理有一个奇怪的行为。我有一个主控和一个单独的构建代理,可以访问 docker.
而我 运行 构建代理上的以下管道脚本:
node {
sh "id"
sh "echo $PATH"
sh "docker ps"
docker.image("node:latest").inside("") {
sh "npm --version"
}
}
我得到以下输出:
Running on docker-agent in /home/jenkins/workspace/test
[Pipeline] {
[Pipeline] sh
[test] Running shell script
+ id
uid=1000(jenkins) gid=1000(jenkins) groups=900(docker),1000(jenkins),1000(jenkins)
[Pipeline] sh
[test] Running shell script
+ echo /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[Pipeline] sh
[test] Running shell script
+ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[Pipeline] sh
[test] Running shell script
+ docker inspect -f . node:latest
.
[Pipeline] withDockerContainer
[Pipeline] // withDockerContainer
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
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)
Also: hudson.remoting.Channel$CallSiteStackTrace: Remote call to docker-agent
at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1741)
at hudson.remoting.UserRequest$ExceptionResponse.retrieve(UserRequest.java:357)
at hudson.remoting.Channel.call(Channel.java:955)
at hudson.Launcher$RemoteLauncher.launch(Launcher.java:1058)
at hudson.Launcher$ProcStarter.start(Launcher.java:454)
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:270)
at org.jenkinsci.plugins.workflow.cps.DSL.invokeMethod(DSL.java:180)
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 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.GeneratedMethodAccessor94.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.call(Continuable.java:174)
at com.cloudbees.groovy.cps.Continuable.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.CpsThread.runNextChunk(CpsThread.java:174)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access0(CpsThreadGroup.java:83)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.call(CpsThreadGroup.java:244)
at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.call(CpsThreadGroup.java:232)
at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService.call(CpsVmExecutorService.java:64)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at hudson.remoting.SingleLaneExecutorService.run(SingleLaneExecutorService.java:131)
at jenkins.util.ContextResettingExecutorService.run(ContextResettingExecutorService.java:28)
at jenkins.security.ImpersonatingExecutorService.run(ImpersonatingExecutorService.java:59)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
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:935)
at hudson.Launcher$ProcStarter.start(Launcher.java:454)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1312)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1265)
at hudson.remoting.UserRequest.perform(UserRequest.java:212)
at hudson.remoting.UserRequest.perform(UserRequest.java:54)
at hudson.remoting.Request.run(Request.java:369)
at hudson.remoting.InterceptingExecutorService.call(InterceptingExecutorService.java:72)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Finished: FAILURE
输出显示,docker ps 工作正常,当我 运行 它作为 shell。当我 运行 使用 docker 构建步骤时,它会导致给定的异常。
知道我做错了什么吗?
您是否已经像他们在 https://jenkins.io/doc/book/pipeline/docker/ 中所说的那样尝试过?
你需要 c -> 如:
node {
sh "id"
sh "echo $PATH"
sh "docker ps"
docker.image("node:latest").inside("") { c ->
sh "npm --version"
}
}
另一个例子:https://github.com/jenkinsci/pipeline-examples/pull/83/files
问题解决了。它有两个问题。
首先,我为构建代理设置了 PATH,它与 shell 命令一起工作正常,但管道无法与它一起工作。虽然 docker 位于 /usr/local/bin,但管道找不到它。它只知道 /usr/bin:/usr/sbin.
其次,我删除了 jenkins 构建代理配置中的 PATH 环境变量,并在 /usr/bin 中为 docker 创建了一个符号 link。
现在我的管道工作了。
Docker 插件从 java 启动 docker 并且不使用设置中的环境变量。我解决了将 PATH 添加到 jenkins-lts.plist
并重新启动 Jenkins
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
我终于通过在Prefix Start Agent Command
中添加export PATH="$PATH:/usr/local/bin";
解决了这个问题。
打开 管理 Jenkins -> 管理节点和云 -> -> 配置 - > 点击 Launch method
下的 高级 -> 添加 export PATH="$PATH:/usr/local/bin";
到 Prefix Start Agent Command
。
然后重新启动 Jenkins,它应该可以正常工作。