![](/img/trans.png)
[英]Jenkins job unable to pass integer parameters into python script during build
[英]Unable to run python script during Jenkins build
问题:
我有一个执行Shell脚本的Jenkins构建步骤。 该脚本依次调用执行某些加密功能的python脚本。 但是,当执行生成时,出现以下错误。
Traceback (most recent call last):
File "./xyz.py", line 4, in <module>
import rsa
ImportError: No module named 'rsa'
Jenkins的节点具有两个版本的python-2.7(默认)和3.4,并且为两个版本都安装了rsa
。 我什至在从属服务器本身上运行了脚本(使用3.4版),并且运行良好。
到目前为止,我所做的是:
我正在使用EnvInject插件将PYTHONPATH
指向正确的位置。 没有它,我发现PYTHONPATH
是未定义的。
使用默认版本,我的脚本以以下代码开头: #!/usr/bin/env python
詹金斯的输出:
[EnvInject] - Executing scripts and injecting environment variables after the SCM step.
[EnvInject] - Injecting as environment variables the properties content
PYTHONPATH=/usr/local/lib/python2.7
[EnvInject] - Variables injected successfully.
[demo] $ /bin/sh -xe /tmp/hudson9217742060700174209.sh
+ export PYTHONPATH=/jenkins/workspace/demo:/usr/local/lib/python2.7
+ echo /jenkins/workspace/demo:/usr/local/lib/python2.7
/jenkins/workspace/demo:/usr/local/lib/python2.7
+ ./abc.sh
/usr/bin/env: python: No such file or directory
在这种情况下,Shebang是#!/usr/bin/env python3
詹金斯的输出:
[EnvInject] - Executing scripts and injecting environment variables after the SCM step.
[EnvInject] - Injecting as environment variables the properties content
PYTHONPATH=/usr/local/lib/python3.4/
[EnvInject] - Variables injected successfully.
[demo] $ /bin/sh -xe /tmp/hudson4592372533933414288.sh
+ export PYTHONPATH=/jenkins/workspace/demo:/usr/local/lib/python3.4/
+ echo /jenkins/workspace/demo:/usr/local/lib/python3.4/
/jenkins/workspace/demo:/usr/local/lib/python3.4/
+ ./abc.sh
Traceback (most recent call last):
File "./xyz.py", line 4, in <module>
import rsa
ImportError: No module named 'rsa'
我什至尝试在脚本本身中执行sys.path.append(os.environ['/usr/local/lib/python3.4/dist-packages/rsa'])
,但问题仍然存在。
谁能帮我解决这个问题? 谢谢。
PS-我对Python的了解非常有限。
据我所记得,我的Python脚本也有类似的问题,最后我通过使用
python xyz.py
代替
./xyz.py
不幸的是,我无法解释为什么它会以这种方式起作用,而不能以其他方式解释,但就我而言,它可以解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.