【问题标题】:Cannot execute shell script despite giving a path尽管给出了路径,但无法执行 shell 脚本
【发布时间】:2021-10-28 23:40:53
【问题描述】:

这是控制台输出中显示的错误。 给定 python 配置的特定路径。还在系统和用户环境变量中指定了路径。

Running as SYSTEM
Building on master in workspace C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\pyproj
[pyproj] $ python C:\Windows\TEMP\jenkins1868508063547381339.py
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
    at java.base/java.lang.ProcessImpl.create(Native Method)
    at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:487)
    at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:154)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
Caused: java.io.IOException: Cannot run program "python" (in directory "C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins\.jenkins\workspace\pyproj"): CreateProcess error=2, The system cannot find the file specified
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
    at hudson.Proc$LocalProc.<init>(Proc.java:253)
    at hudson.Proc$LocalProc.<init>(Proc.java:222)
    at hudson.Launcher$LocalLauncher.launch(Launcher.java:996)
    at hudson.Launcher$ProcStarter.start(Launcher.java:508)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:144)
    at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:92)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:21)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:808)
    at hudson.model.Build$BuildExecution.build(Build.java:199)
    at hudson.model.Build$BuildExecution.doRun(Build.java:164)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:516)
    at hudson.model.Run.execute(Run.java:1889)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:100)
    at hudson.model.Executor.run(Executor.java:433)
Build step 'Execute Python script' marked build as failure
Finished: FAILURE

【问题讨论】:

  • 这不是shell脚本;您正在尝试执行 Python 脚本。如果您真的想执行一个 shell 脚本,请将构建操作从“执行 Python 脚本”更改为“执行一个 shell 脚本”(尽管 Windows 也不太可能默认安装与 Unix 兼容的 shell)。
  • 请澄清您的具体问题或提供其他详细信息以准确突出您的需求。正如目前所写的那样,很难准确地说出你在问什么。

标签: python jenkins path


【解决方案1】:

它抱怨找不到python。您没有指定 Python 二进制文件的完整路径。

你确定 Python 甚至安装在这个系统上吗?

根据安装方式和安装位置,尝试将c:\python39 之类的内容添加到您的PATH;详情请见How to set the PATH environment variable in Jenkins configuration on Windows?

【讨论】:

  • 在非 Windows 操作系统上,这更简单一些,但如果您在 /opt/extras/python 这样的奇怪地方安装了自定义 Python,则必须将其添加到 PATH 的前面说服 Jenkins 使用该自定义版本,非常相似。 (虽然可能改为将/usr/local/bin/python 的符号链接添加到您要使用的 Python 二进制文件。)
猜你喜欢
  • 1970-01-01
  • 2011-04-07
  • 1970-01-01
  • 2011-09-04
  • 2018-12-10
  • 2017-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多