I am having module import errors in Jenkins despite setting my path and python path based on questions here on stack overflow
I have tried this
Jenkins: putting my Python module on the PYTHONPATH
and this
Python module import failure in Jenkins
This same command runs on my local machine without any import issues but fails on Jenkins
The command
#!/bin/bash
export PYTHONPATH=$WORKSPACE:$PYTHONPATH
export PATH=$WORKSPACE:$PATH
export DJANGO_SETTINGS_MODULE=myapp.settings.test
echo "Working directory: "
pwd
echo "path: "
echo $PATH
echo "Python path: "
echo $PYTHONPATH
/home/adminuser/.virtualenvs/myapp/bin/python myapp/manage.py jenkins --project-apps-tests --enable-coverage --settings=myapp.settings.test
The build error
Working directory:
/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace
path:
/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace/myapp/apps/:/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games
Python path:
/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace/myapp/apps/:/home/adminuser/.virtualenvs/myapp/bin:/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace:
-------- USING TEST SETTINGS ------
Traceback (most recent call last):
......
File "/var/lib/jenkins/jobs/myapp_QA_TESTS/workspace/myapp/apps/accounts/models.py", line 18, in <module>
from apps.registration.tokens.token import GenerateToken
ImportError: No module named registration.tokens.token
My file structure
overview
myapp/
├── apps
│ ├── __init__.py
│ ├── accounts
│ ├── registration
├── myapp
│ ├── __init__.py
│ ├── celery.py
│ ├── settings
│ ├── urls.py
│ └── wsgi.py
├── manage.py
view into the module directories
myapp/apps/registration/tokens
├── __init__.py
└── token.py
myapp/apps/accounts/
├── __init__.py
├── models.py
I have tried even appending the workspace directory and the virtualenv path to both PATH and PYTHONPATH, i also even added the module directory to the PATH and PYTHONPATH
I get the same error when i run the command on the server itself. Could this be caused by the fact that my virtualenv was created by admin user, but now Jenkins is trying to use it, But all packages load
How do I fix this import error, any assistance is appreciated