Jenkinsfile and Python virtualenv
<p>I am trying to setup a project that uses the shiny new Jenkins pipelines, more specifically a multibranch project.</p>

<p>I have a <code>Jenkinsfile</code> created in a test branch as below:</p>

<pre><code>node {
    stage 'Preparing VirtualEnv'
    if (!fileExists('.env')){
        echo 'Creating virtualenv ...'
        sh 'virtualenv --no-site-packages .env'
    }
    sh '. .env/bin/activate'
    sh 'ls -all'
    if (fileExists('requirements/preinstall.txt')){
        sh 'pip install -r requirements/preinstall.txt'
    }
    sh 'pip install -r requirements/test.txt'
    stage 'Unittests'
    sh './manage.py test --noinput'
}
</code></pre>

<p>It's worth noting that <code>preinstall.txt</code> will update pip.</p>

<p>I am getting error as below:</p>

<pre><code>OSError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/pip'
</code></pre>

<p>Looks like it's trying to update pip in global env instead of inside virtualenv, and looks like each <code>sh</code> step is on its own context, how do I make them to execute within the same context?</p>