How can I write a Groovy Jenkinsfile for a Django application to run my tests?

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:

  • aws Push from django python causes my server database to be replaced by local database
  • How to preserve the file permission in git?
  • Retrieve private repository commits from github
  • Creating a submodule in a git project
  • How to remove lines pip.vcs: Registered VCS backend: *** from log file
  • Django errors when removing .pyc files from repo
  • 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'
    }
    

  • The server rejected the connection: None of the protocols were accepted
  • Trouble with SVN post-commit and Jenkins
  • How to exclude south migrations from public repositories?
  • Fail Pipeline in Jenkins
  • What is the default Jenkins password?
  • Unknown option git config --local reported by Jenkins
  • One Solution collect form web for “How can I write a Groovy Jenkinsfile for a Django application to run my tests?”

    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"
    
    Git Baby is a git and github fan, let's start git clone.