【问题标题】:Getting " Cannot run program "bash"" while building chef in jenkins在詹金斯构建厨师时获得“无法运行程序“bash””
【发布时间】:2015-08-09 15:57:07
【问题描述】:

我在 jenkins 中安装了 chef-plugin 并做了以下配置: 在远程主机上运行 Chef 客户端:

enabled: checked
ssh host: "remote host"
ssh login: root
chef_json template: "{
  "run-list" :[
   "recipe[test]"
   ]
}"

color output: checked

并得到以下错误:

Started by user swetha sreeramoju
Building in workspace C:\.jenkins\workspace\chef-sample
[2015-05-27 19:06:44 +0530] INFO: [34m[47mrendering ERB template[0m[0m
[2015-05-27 19:06:44 +0530] INFO: [34m[47mparsing JSON string[0m[0m
[2015-05-27 19:06:44 +0530] INFO: [34m[47msaving JSON to file[0m[0m
[2015-05-27 19:06:44 +0530] INFO: [2m[1m[34m[47m[4mchef json url[0m[0m[0m[0m[0m[34m[47m : http://localhost:8080/jenkins//job/chef-sample/ws/chef.json[0m[0m
[2015-05-27 19:06:44 +0530] INFO: [2m[1m[34m[47m[4mhost[0m[0m[0m[0m[0m[34m[47m : 10.0.12.209[0m[0m
$ bash -c "ssh root@10.0.12.209 sudo chef-client -l info -j http://localhost:8080/jenkins//job/chef-sample/ws/chef.json  "
ERROR: Cannot run program "bash": CreateProcess error=2, The system cannot find the file specified (Java::JavaIo::IOException)
java.lang.ProcessBuilder.start(Unknown Source)
hudson.Proc$LocalProc.<init>(Proc.java:244)
hudson.Proc$LocalProc.<init>(Proc.java:216)
hudson.Launcher$LocalLauncher.launch(Launcher.java:816)
hudson.Launcher$ProcStarter.start(Launcher.java:382)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.jruby.javasupport.JavaMethod.invokeDirectWithExceptionHandling(JavaMethod.java:440)
org.jruby.javasupport.JavaMethod.invokeDirect(JavaMethod.java:304)
org.jruby.java.invokers.InstanceMethodInvoker.call(InstanceMethodInvoker.java:52)
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:134)
org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:64)
org.jruby.ast.CallOneArgNode.interpret(CallOneArgNode.java:57)
org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:112)
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:126)
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:163)
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:70)
org.jruby.ast.FCallSpecialArgNode.interpret(FCallSpecialArgNode.java:45)
org.jruby.ast.CallNoArgNode.interpret(CallNoArgNode.java:64)
org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:112)
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:126)
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:163)
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:70)
org.jruby.ast.CallManyArgsNode.interpret(CallManyArgsNode.java:59)
org.jruby.ast.CallOneArgFixnumNode.interpret(CallOneArgFixnumNode.java:59)
org.jruby.ast.IfNode.interpret(IfNode.java:110)
org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
org.jruby.ast.IfNode.interpret(IfNode.java:116)
org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:268)
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:220)
org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:236)
org.jruby.ast.CallThreeArgNode.interpret(CallThreeArgNode.java:61)
org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
org.jruby.evaluator.ASTInterpreter.INTERPRET_BLOCK(ASTInterpreter.java:112)
org.jruby.runtime.Interpreted19Block.evalBlockBody(Interpreted19Block.java:209)
org.jruby.runtime.Interpreted19Block.yield(Interpreted19Block.java:160)
org.jruby.runtime.Interpreted19Block.yieldSpecific(Interpreted19Block.java:133)
org.jruby.runtime.Block.yieldSpecific(Block.java:99)
org.jruby.ast.ZYieldNode.interpret(ZYieldNode.java:25)
org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
org.jruby.ast.BlockNode.interpret(BlockNode.java:71)
org.jruby.ast.RescueNode.executeBody(RescueNode.java:224)
org.jruby.ast.RescueNode.interpret(RescueNode.java:119)
org.jruby.ast.BeginNode.interpret(BeginNode.java:83)
org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:204)
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:196)
org.jruby.runtime.callsite.CachingCallSite.callBlock(CachingCallSite.java:177)
org.jruby.runtime.callsite.CachingCallSite.callIter(CachingCallSite.java:188)
org.jruby.ast.FCallOneArgBlockNode.interpret(FCallOneArgBlockNode.java:34)
org.jruby.ast.NewlineNode.interpret(NewlineNode.java:105)
org.jruby.evaluator.ASTInterpreter.INTERPRET_METHOD(ASTInterpreter.java:75)
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:112)
org.jruby.internal.runtime.methods.InterpretedMethod.call(InterpretedMethod.java:126)
org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:163)
org.jruby.javasupport.proxy.JavaProxyConstructor$2.invoke(JavaProxyConstructor.java:224)
org.jruby.proxy.hudson.tasks.Builder$Proxy2.perform(Unknown Source)
hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:764)
hudson.model.Build$BuildExecution.build(Build.java:205)
hudson.model.Build$BuildExecution.doRun(Build.java:162)
hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
hudson.model.Run.execute(Run.java:1744)
hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
hudson.model.ResourceController.execute(ResourceController.java:98)
hudson.model.Executor.run(Executor.java:374)

Build step 'Run chef client on remote host' marked build as failure
Finished: FAILURE

Chef客户端和服务器运行在Linux机器上,jenkins配置在Windows7上。

【问题讨论】:

  • 你的系统中的 bash 在哪里?
  • 那里的服务器显然不是 linux。查看Building in workspace 行。这显然是一条 Windows 路径。
  • 我的机器里有腻子。

标签: linux bash ssh jenkins chef-infra


【解决方案1】:

问题似乎更广泛,正如这里SSH+slaves+and+Cygwin 所解释的那样:

这是因为 Jenkins 试图调用 Windows API 并执行“/bin/bash”而不经过 Cygwin 路径转换。 Windows 将 /bin/bash 解释为 c:\bin\bash.exe,除非该路径存在,否则它将失败。

一个快速的解决方案是从一个 linux 节点传递。

另一种快速的可能性是从 Chef-client linux 机器中创建一个 on-demand Jenkins 节点(单击几下)并在那里运行正确的 shell 行(尽管它可能更像是一个 hack) :

chef-client -l info -j http://localhost:8080/jenkins//job/chef-sample/ws/chef.json 

【讨论】:

  • 我已经尝试在 Putty 中运行上述命令。但我面临连接错误。
  • 显然您必须将 {localhost} 替换为运行 Jenkins 服务器的机器的真实 IP 或主机名。然后 Jenkins 服务器需要对主厨客户端可见。无论如何,正如 Sven 所建议的那样,采用这种方法有点变态。如果你有一个全新的设置 - 并且没有 IT 包含 - 我会将 Jenkins 服务器移动到一个好的旧 linux 系统。
  • 我也是这样做的。我已经替换了 localhost 并添加了运行 jenkins 的 ipaddress。出现连接错误。有没有其他方法可以解决这个问题?
  • 从机器上的浏览器中检查您是否拥有访问localhost:8080/jenkins/job/chef-sample/ws/chef.json 的凭据。此外,如果不需要,我会删除第二个“/”。
  • 另一个问题是您必须在 W7 防火墙上启用 8080。
【解决方案2】:

Jenkins客户端和服务器运行在Linux机器上,jenkins配置在Windows7上。

这没有任何意义。

  • 什么是“Jenkins 客户端”?你用来连接 Jenkins 的浏览器?您可以通过任何操作系统上的任何浏览器进行连接。它对执行没有任何影响。执行发生在主/从节点上。
  • “Jenkins [...] 服务器正在 Linux 中运行”。好的。但是那为什么你的日志说Building in workspace C:\.jenkins\workspace\chef-sample。显然它在 Windows 节点上运行。所以要么有一个你没有提到的 Windows 从节点,要么 Jenkins 服务器不在 Linux 上而是在 Windows 上。
  • “Jenkins 在 Windows7 中配置”。好吧,这只会继续增加混乱。 Jenkins 服务器是运行在 Windows 上还是 Linux 上,你刚才说的是“Linux”。

您的问题是您无法在 Windows 上的 Jenkins 中运行 bash(一切都表明这里就是这种情况),除非您在 Windows 上安装了 bash 等效(Cygwin)

【讨论】:

  • Jenkins 在 Windows 7 中运行,Chef 客户端和服务器在 Linux 机器中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-12
  • 2015-11-03
相关资源
最近更新 更多