Skip to content
Snippets Groups Projects
Jenkinsfile 2.31 KiB
// make sure the pip cache is accessible
def container_args = "-v ${env.JENKINS_HOME}/.cache:/cache:rw,z -e XDG_CACHE_HOME=/cache"

pipeline {
    agent none
    stages {
        stage('init') {
            agent any
            steps {
                script {
                    def matcher = env.GIT_URL =~ /\/(.*)\.git/

                    if(matcher.find()) {
                        gitProjectId = matcher[0][1];
                    }
                }
                echo gitProjectId
            }
        }
        stage('test') {
            parallel {

                stage('test Python 3.6.8 (Centos 7)') {
                    agent {
                        docker {
                            image 'python:3.6.8'
                            args container_args
                        }
                    }
                    steps {
                        run_unit_tests('py36')
                    }
                }

                stage('test Python 3.7.6') {
                    agent {
                        docker {
                            image 'python:3.7.6'
                            args container_args
                        }
                    }
                    steps {
                        run_unit_tests('py37')
                    }
                }

                stage('test Python 3.8.3') {
                    agent {
                        docker {
                            image 'python:3.8.3'
                            args container_args
                        }
                    }
                    steps {
                        run_unit_tests('py38')
                    }
                }

            }
        }
        stage('SonarQube analysis') {
            agent any
            steps {
                script {
                    // must match 'Name' from Jenkins 'Global Tool Configuration'
                    scannerHome = tool 'sonar-scaner';
                }
                // must match 'Name' from Jenkins 'Configure System'
                withSonarQubeEnv('Project SonarQube') {
                    sh "${scannerHome}/bin/sonar-scanner -Dproject.settings=./sonar.properties"
                }
            }

        }
    }
}

void run_unit_tests(tox_env) {
    sh 'python -m venv venv'
    sh 'venv/bin/pip install tox'
    sh "venv/bin/tox -e $tox_env"
}