I have recently started using Jenkins and I am wanting to use Multibranch Pipelines so I can test the various feature branches in my project.
The project is using django 1.8. So far my Jenkinsfile looks like this and fails in the testing stage as django can not find my settings file even though it is there:
node {
// Mark the code checkout 'stage'....
stage 'Checkout'
// Get the code from a GitHub repository
git credentialsId: 'mycredentials', url: 'https://github.com/<user>/<project>/'
// Mark the code build 'stage'....
stage 'Build'
env.WORKSPACE = pwd()
sh 'virtualenv --python=python34 venv'
sh 'source venv/bin/activate'
sh 'pip install -r requirements.txt'
env.DJANGO_SETTINGS_MODULE = "<appname>.settings.jenkins"
// Start the tests
stage 'Test'
sh 'python34 manage.py test --keepdb'
}
venv/bin/activate
does no more than setting up proper environmental paths.
You can do it on your own by adding at the beginning assuming that env.WORKSPACE
is your project directory:
env.PATH="${env.WORKSPACE}/venv/bin:/usr/bin:${env.PATH}"
Later, if you want to call virtualenved python, just need to prepend it with specified path like here:
stage 'Test'
sh "${env.WORKSPACE}/venv/bin/python34 manage.py test --keepdb'
Or to call pip
sh "${env.WORKSPACE}/venv/bin/pip install -r requirements.txt"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With