繁体   English   中英

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

[英]NameError: name 'python3' is not defined [Jenkins]

我的任务很简单。 我已经编写了一个脚本job.sh来调用python脚本

#!/bin/bash
python3 pythonscript/script.py

我希望此script.py每小时运行一次,因此我在Jenkins的帮助下并在项目中配置了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

选项1:

尝试更改shebang,使其可以与特定版本的Python一起运行

#!/usr/bin/python2.6

选项2:

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

 python pythonscript/script.py

问题2

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM