我正在尝试运行 Python 作业。我创建了以下文件夹:
C:\Users\herod\jenkins_ws\workspace\window_testing
并向其中添加脚本“testing.py”。
该脚本非常简单:
if __name__ == "__main__":
print "hellow world !"
f = open('test_log.txt','w')
f.write("hello\n")
f.close
但是从 Jenkins 运行它时出现以下错误(如果我从命令行运行它它可以工作):
>Building remotely on windows1 (widndows_genereal) in workspace C:\Users\herod\jenkins_ws\workspace\window_testing
[window_testing] $ python C:\windows\TEMP\hudson5234791200924972506.py
The system cannot find the file specified
FATAL: command execution failed
java.io.IOException: Cannot run program "python" (in directory "C:\Users\herod\jenkins_ws\workspace\window_testing"): CreateProcess error=2, The system cannot find the file specified
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:775)
at hudson.Launcher$ProcStarter.start(Launcher.java:355)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1024)
at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:991)
我究竟做错了什么 ?
这是我尝试过的:
在构建部分的作业配置中,我选择“执行Python脚本”,然后输入testing.py文件 - 不起作用。
我还尝试输入 python test.py 和 python.exe testing.py - 不起作用。
尝试在“脚本”编辑文本中编写 python 脚本 - 不起作用。
如果我将执行类型从 python 更改为批处理文件,那么它显示它通过了,但实际上它没有运行 python 脚本。
update2:(尝试 Technext 解决方案后)我收到下一个错误:
Building remotely on windows1 (widndows_genereal) in workspace C:\Users\herod\jenkins_ws\workspace\window_testing
[window_testing] $ python C:\Users\herod\AppData\Local\Temp\hudson4767788636447260218.py
Traceback (most recent call last):
File "C:\Users\herod\AppData\Local\Temp\hudson4767788636447260218.py", line 1, in <module>
testing.py
NameError: name 'testing' is not defined
Build step 'Execute Python script' marked build as failure
Finished: FAILURE
每当在批处理文件中将 python 作为命令运行时,请提供 Python 可执行文件的完整路径,否则您必须在 Jenkins 环境中配置该路径。假设你的 python 可执行文件保存在C:\Python27
文件夹,然后执行以下命令:
C:\Python27\python.exe <full path of python file to execute>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)