NameError:未定义名称“ python3” [Jenkins]

时间:2018-10-16 08:49:48

标签: python jenkins

我要做的任务很简单。 我已经编写了一个脚本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.

1 个答案:

答案 0 :(得分:2)

问题1

选项1:

尝试更改shebang,使其可以在特定版本的Python上运行

#!/usr/bin/python2.6

选项2:

尝试将其作为python2而不是python3运行

 python pythonscript/script.py

问题2

您可以使用pwd来获取脚本的绝对路径。然后您可以将其添加到jenkins脚本中。