无法使用jenkins运行python脚本 [英] failed to run python scripts with jenkins

查看:1575
本文介绍了无法使用jenkins运行python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行Python作业.我创建了以下文件夹:

I am trying to run a Python job. I have created the following folder:

C:\ Users \ herod \ jenkins_ws \ workspace \ window_testing

C:\Users\herod\jenkins_ws\workspace\window_testing

并在其中添加了脚本"testing.py".

and added the script "testing.py" to it.

脚本非常简单:

if __name__ == "__main__":
    print "hellow world !"
    f = open('test_log.txt','w')
    f.write("hello\n")
    f.close

但是从Jenkins运行它时出现以下错误(如果我从命令行运行它会起作用):

But I am getting the following error when running it from Jenkins (if I run it from command line it works):

>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文件-不起作用.

  • in the configure for the job at the build section I choose "execute python script" and than entered the testing.py file - not working.

我还尝试输入python testing.py和python.exe testing.py-不起作用.

I also tried to enter there python testing.py and python.exe testing.py - not working.

试图在脚本"编辑文本中编写python脚本-不起作用.

Trying to write a python script in the "script" edit text - not working.

如果我将执行类型从python更改为批处理文件,则表明它可以通过,但实际上它没有运行python脚本.

If I change the execute type from python to batch file and than it shows that it pass but actually it didn't run the python script.

update2:(尝试使用Technext解决方案后),我得到了下一个错误:

update2: (after trying Technext solution) I got the next error:

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脚本在命令行上运行良好,但是在通过Jenkins运行时出现问题,因此很可能意味着 user 与哪个Jenkins正在运行存在查找Python可执行文件python.exe的问题.如果您有可能(并且可行)更改Jenkins用户,则请使用我描述的过程

Since the python script runs fine on the command line but has issues when running through Jenkins, it most probably means that the user with which Jenkins is running has issues finding Python executable i.e., python.exe. If it is possible (and feasible) for you to change the Jenkins user, then please change it using the process i described here. Make it run as the same user with which you are running the program successfully on command prompt.

这篇关于无法使用jenkins运行python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆