This is a tutorial on setting up virtualenv to work in Jenkins.
Setting up VirtualEnv in Jenkins
At the time of writing, I was using Jenkins 1.430.
The first thing you will need to do is to setup your PATH environment variable to “.env/bin:$PATH” as show below by navigating to “Manage Jenkins” > “Configure System”:

Configure PATH variable
Next, you will need to add a build step which will check to create/use the virtual environment. Here I also install unittest-xml-reporting and coverage tools.
if [ -d ".env" ]; then
echo "**> virtualenv exists"
else
echo "**> creating virtualenv"
virtualenv .env
fi
source .env/bin/activate
pip install -r requirements.txt
pip install unittest-xml-reporting==1.2
pip install coverage==3.5.1b1
You ARE using a requirements.txt file to install dependencies for your project right? If not, see http://www.pip-installer.org/en/latest/requirement-format.html.
Then you can continue your build as normal. This concludes the tutorial to use virtualenv in Jenkins/Hudson.
Source: http://jenkins-ci.org/content/python-love-story-virtualenv-and-hudson
Leave your question/comment below!
