How to write a Groovy Jenkins file for a Django application to run my tests?

I recently started using Jenkins, and I want to use Multibranch Pipelines so that I can test various function branches in my project.

The project uses django 1.8. So far, my Jenkinsfile looks and does not work at the testing stage, since django can not find my settings file, even if it is:

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'
}
+4
source share
1 answer

venv/bin/activate does nothing more than tweak the right environmental paths.

You can do it yourself by adding at the beginning, assuming that env.WORKSPACEthis is the directory of your project:

env.PATH="${env.WORKSPACE}/venv/bin:/usr/bin:${env.PATH}"

, virtualenved python, , :

stage 'Test'
sh "${env.WORKSPACE}/venv/bin/python34 manage.py test --keepdb'

pip

sh "${env.WORKSPACE}/venv/bin/pip install -r requirements.txt"
+1

Source: https://habr.com/ru/post/1648331/


All Articles