Derek Kwok's Blog

Blog about Software Development, Techniques and Discoveries.

Setting up virtualenv in Jenkins/Hudson

| 0 comments

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.

Adding virtualenv setup in build step

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!

Leave a Reply

Required fields are marked *.

*