Jenkins ModuleNotFoundError:没有名为'jenkinsapi.jenkins'的模块; 'jenkinsapi'不是一个软件包

时间:2019-03-21 21:45:21

标签: python jenkins

我有一个运行Centos 6的虚拟机。我有一个尝试在Jenkins中运行的简单python脚本。我可以在虚拟机上成功运行该脚本,但是一旦该脚本存在于Jenkins Workspace中,便无法运行。

[root@vm921.dev.ut1 ~]# /usr/local/bin/python3.7
Python 3.7.0 (default, Mar 20 2019, 14:31:35)
[GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from jenkinsapi.jenkins import Jenkins
>>>

正如您在上面看到的,我可以从命令行成功导入jenkinsapi模块,但是我无法在Jenkins中运行它。

我在pip3.7上安装了python3.7。 jenkinsapi软件包存在,但是我无法从工作空间目录执行脚本。

    [EnvInject] - Loading node environment variables.
Building on master in workspace /home/jenkins/workspace/jenkinsapi
[jenkinsapi] $ /bin/sh -xe /tmp/jenkins5545466490229682574.sh
+ cd /home/ccuevas
+ pip3 install jenkinsapi
Requirement already satisfied: jenkinsapi in /usr/local/python37/lib/python3.7/site-packages (0.3.8)
Requirement already satisfied: pytz>=2014.4 in /usr/local/python37/lib/python3.7/site-packages (from jenkinsapi) (2018.9)
Requirement already satisfied: requests>=2.3.0 in /usr/local/python37/lib/python3.7/site-packages (from jenkinsapi) (2.21.0)
Requirement already satisfied: six>=1.10.0 in /usr/local/python37/lib/python3.7/site-packages (from jenkinsapi) (1.12.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/python37/lib/python3.7/site-packages (from requests>=2.3.0->jenkinsapi) (2019.3.9)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/python37/lib/python3.7/site-packages (from requests>=2.3.0->jenkinsapi) (3.0.4)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/python37/lib/python3.7/site-packages (from requests>=2.3.0->jenkinsapi) (1.24.1)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/python37/lib/python3.7/site-packages (from requests>=2.3.0->jenkinsapi) (2.8)
+ python3 jenkins.py
Traceback (most recent call last):
  File "jenkins.py", line 1, in <module>
    from jenkinsapi.jenkins import Jenkins
ModuleNotFoundError: No module named 'jenkinsapi'
Build step 'Execute shell' marked build as failure
Finished: FAILURE

我尝试卸载jenkinsapi软件包并重新安装。

1 个答案:

答案 0 :(得分:1)

辛苦劳动后,我解决了这个问题。问题是我在詹金斯(Jenkins)工作的文件名被命名为'jenkinsapi.py'。这项工作试图从第一行“导入jenkinsapi”中导入文件本身,而不是“ jenkinsapi”模块。我将Jenkins中的文件重命名为其他名称,并且不再发生错误。