Reputation: 2668
I am trying to run a Python job. I have created the following folder:
C:\Users\herod\jenkins_ws\workspace\window_testing
and added the script "testing.py" to it.
The script is very simple:
if __name__ == "__main__":
print "hellow world !"
f = open('test_log.txt','w')
f.write("hello\n")
f.close
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)
What am I doing wrong ?
Here is what I have tried:
in the configure for the job at the build section I choose "execute python script" and than entered the testing.py file - not working.
I also tried to enter there python testing.py and python.exe testing.py - not working.
Trying to write a python script in the "script" edit text - not working.
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: (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
Upvotes: 2
Views: 25674
Reputation: 168
When you install Python in Windows, there is an option to "Add Python to System Path" which you should make sure is selected. You can safely install over your existing Python if you're not sure. This worked for us in Jenkins using the Python plugin.
Upvotes: 1
Reputation: 479
Whenever running python as a command in batch file, Give the full path of Python executable or you will have to configure the path in the Jenkins environment. Say your python executable is kept in C:\Python27
folder, then execute the following:
C:\Python27\python.exe <full path of python file to execute>
Upvotes: 2
Reputation: 8117
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.
Upvotes: 1