我正在尝试在Jenkins中执行命令shell,我正在使用Windows 7.在控制台输出中,我有这样的:
Building in workspace C:\Program Files (x86)\Jenkins\workspace\test
[test] $ sh -xe C:\Windows\TEMP\hudson6299483223982766034.sh
The system cannot find the file specified
FATAL: L'exécution de la commande a échoué.
java.io.IOException: Cannot run program "sh" (in directory "C:\Program Files (x86)\Jenkins\workspace\test"): CreateProcess error=2, Le fichier spécifié est introuvable
at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:816)
at hudson.Launcher$ProcStarter.start(Launcher.java:382)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:97)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1744)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:374)
Caused by: java.io.IOException: CreateProcess error=2, Le fichier spécifié est introuvable
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 16 more
Build step 'Exécuter un script shell' marked build as failure
[BFA] Scanning build for known causes...
[BFA] No failure causes found
[BFA] Done. 0s
Finished: FAILURE
任何的想法?
对于Windows slave,请使用Execute Windows batch command
。
对于像Linux或Mac这样类Unix的奴隶,可以选择Execute shell
。
据我所知,Windows不支持开箱即用的shell脚本。您可以安装Cygwin或Git for Windows,转到Manage Jenkins> Configure System Shell并将其指向安装中找到的sh.exe文件的位置。例如:
C:\Program Files\Git\bin\sh.exe
我发现了另一种选择。这个更好,因为它允许我在简单的sh "something"
的管道脚本中使用shell。
将文件夹添加到系统PATH。右键单击“计算机”,单击“属性”>“高级系统设置”>“环境变量”,将C:\Program Files\Git\bin\
添加到系统“路径”属性中。
重要说明:出于某种原因,我不得不将其添加到系统范围的路径中,即使Jenkins在此用户上运行,添加到用户路径也不起作用。
一个重要的说明(谢谢bugfixr!):
这有效。应该注意的是,您需要重新启动Jenkins才能获取新的PATH变量。我只是去了我的服务并从那里重申了它。
免责声明:由于我不使用英文Windows,名称可能略有不同。
错误显示脚本不存在
该文件不存在。检查你的完整路径
C:\Windows\TEMP\hudson6299483223982766034.sh
The system cannot find the file specified
此外,要将.sh脚本启动到Windows中,您需要安装CYGWIN并将其配置到您的路径中
确认该脚本存在。
进入jenkins脚本,执行以下操作以确认您确实拥有该文件
cd C:\Windows\TEMP\
ls -rtl
sh -xe hudson6299483223982766034.sh
这是因为Jenkins不了解shell路径。在Manage Jenkins - > Configure System - > Shell中,将shell路径设置为
转到Jenkins - >管理Jenkins - >配置系统 - >全局属性选中“环境变量”框并添加JAVA_HOME路径=“C:\ Program Files \ Java \ jdk-10.0.1”
*不要在最后写垃圾箱