我要做的任务很简单。
我已经编写了一个脚本job.sh
来调用python脚本
#!/bin/bash
python3 pythonscript/script.py
我希望这个script.py
每小时运行一次,所以我在詹金斯的帮助下,在项目中配置了job.sh
。
单独运行job.sh
可以很好地工作,但是在Jenkins中运行它时会显示错误:
NameError: name 'python3' is not defined
Build step 'Execute shell' marked build as failure
Finished: FAILURE
script.py中的内容:
for i in range(30):
print("PRINTING FROM PYTHON SCRIPT")
有两个问题:
1) How to resolve the above error
2) The Jenkins job runs in a different folder lets say `(jenkins/jobs/job131.sh)` and my `script.py` is somewhere else `(pythonscript/script.sh)`. How to give the absolute path to my script so that `job.sh` will invoke it without any issue.
答案 0 :(得分:2)
选项1:
尝试更改shebang,使其可以在特定版本的Python上运行
#!/usr/bin/python2.6
选项2:
尝试将其作为python2而不是python3运行
python pythonscript/script.py
您可以使用pwd
来获取脚本的绝对路径。然后您可以将其添加到jenkins脚本中。