3

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/app_verify_auto.py

And get the error:

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

Traceback (most recent call last):

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

    import exit103.data.db as db

ImportError: No module named exit103.data.db

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.

wbest
  • 611
  • 1
  • 6
  • 15

2 Answers2

2

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

Community
  • 1
  • 1
user4395104
  • 231
  • 2
  • 4
0

Faced the same issue.

For others who are reading this, Run the build in your master node. It fixed the problem for me.

Running the build in the slave node doesn't give proper access to all the python modules and other commands such as jq to the workspace.

To ensure that the build only runs in your master node, enter master in the "Restrict where this project can be run" settings like this.

Securiosity
  • 37
  • 11