Python module import failure in Jenkins


I have a project I'm trying to test and run on Jenkins. On my machine it works fine, but when I try to run it in Jenkins, it fails to find a module in the workspace.

In the main workspace directory, I run the command:

python xtests/

And get the error:

+ python /home/tomcat7/.jenkins/jobs/exit103/workspace/xtests/

Traceback (most recent call last):

  File "/home/tomcat7/.jenkins/jobs/exit103/workspace/xtests/", line 19, in <module>

    import as db

ImportError: No module named

Build step 'Execute shell' marked build as failure

Finished: FAILURE

The directory exit103/data exists in the workspace and is a correct path, but python can't seem to find it.

This error exists both with and without virtualenv.

Best Solution

It's may caused by your PATH setting not right in jenkins environment.In fact , the environments for your default user and jenkins-user are not the same.

You may try to find what are the PATH and PYTHONPATH in your jenkins-user environments . Try to run "shell commands" in jenkins "echo $path" and so on to see what's them are.

In most of time , you need to set the PATH by yourself. You may reference this answer. Jenkins: putting my Python module on the PYTHONPATH