Projet

Général

Profil

0001-create-jenkins-pipeline-job-24805.patch

Emmanuel Cazenave, 27 juin 2018 15:33

Télécharger (5,43 ko)

Voir les différences:

Subject: [PATCH] create jenkins pipeline job (#24805)

 Jenkinsfile       | 39 +++++++++++++++++++++++++++++++++++++++
 jenkins.sh        | 25 ++++++++-----------------
 pylint.sh         | 13 +++++++++++++
 tests/settings.py |  2 +-
 tox.ini           | 11 +++++++----
 5 files changed, 68 insertions(+), 22 deletions(-)
 create mode 100644 Jenkinsfile
 create mode 100755 pylint.sh
Jenkinsfile
1
@Library('eo-jenkins-lib@wip/publish_coverage_native') import eo.Utils
2

  
3
pipeline {
4
    agent any
5
    stages {
6
        stage('Unit Tests') {
7
            steps {
8
                sh './jenkins.sh'
9
            }
10
        }
11
        stage('Packaging') {
12
            steps {
13
                script {
14
                    if (env.JOB_NAME == 'authentic2' && env.GIT_BRANCH == 'origin/master') {
15
                        sh 'sudo -H -u eobuilder /usr/local/bin/eobuilder -d jessie authentic'
16
                    }
17
                }
18
            }
19
        }
20
    }
21
    post {
22
        always {
23
            script {
24
                utils = new Utils()
25
                utils.mail_notify(currentBuild, env, 'admin+jenkins-authentic@entrouvert.com')
26
                utils.publish_coverage('coverage-*.xml')
27
                utils.publish_coverage_native(
28
                    'index.html', 'htmlcov-coverage-dj18-authentic-pg', 'Coverage a2')
29
                utils.publish_coverage_native(
30
                    'index.html', 'htmlcov-coverage-dj18-rbac-pg', , 'Coverage rbac')
31
                utils.publish_pylint('pylint.out')
32
            }
33
            junit 'junit-*.xml'
34
        }
35
        success {
36
            cleanWs()
37
        }
38
    }
39
}
jenkins.sh
2 2

  
3 3
set -e
4 4

  
5
./getlasso.sh
6
# SNI support for Debian
7
pip install --upgrade pyOpenSSL ndg-httpsclient pyasn1
8
pip install --upgrade pip\>9
9
pip install --upgrade pylint pylint-django 'django<1.9'
10
pip install --upgrade tox
11
pip install -U 'virtualenv<14'
12
rm -f coverage*.xml junit*.xml
13
if [[ `date +%H%M` < 630 ]]; then
14
	# run full tests (with migrations) at night
15
	tox -r -e 'coverage-dj18-{authentic,rbac}-{pg,sqlite}'
16
else
17
	tox -r -e 'fast-coverage-dj18-{authentic,rbac}-{pg,sqlite}'
18
fi
19
(pylint -f parseable --rcfile /var/lib/jenkins/pylint.django.rc src/authentic2/ | tee pylint.out) || /bin/true
20
./merge-junit-results.py junit-*coverage-dj18-authentic-pg.xml junit-*coverage-dj18-rbac-pg.xml > junit.xml
21
./merge-coverage.py -o coverage.xml coverage-*.xml
5
for DIRECTORY in "htmlcov" "htmlcov-coverage-dj18-authentic-pg" "htmlcov-coverage-dj18-rbac-pg"
6
do
7
    if [ -d "$DIRECTORY" ]; then
8
        rm -r $DIRECTORY
9
    fi
10
done
11

  
12
tox -rv
pylint.sh
1
#!/bin/sh
2

  
3
set -e -x
4
env
5
if [ -f /var/lib/jenkins/pylint.django.rc ]; then
6
	PYLINT_RC=/var/lib/jenkins/pylint.django.rc
7
elif [ -f pylint.django.rc ]; then
8
	PYLINT_RC=pylint.django.rc
9
else
10
	echo No pylint RC found
11
	exit 0
12
fi
13
pylint -f parseable --rcfile ${PYLINT_RC} "$@" | tee pylint.out || /bin/true
tests/settings.py
13 13
    'default': {
14 14
        'ENGINE': os.environ.get('DB_ENGINE', 'django.db.backends.sqlite3'),
15 15
        'TEST': {
16
            'NAME': 'a2-test',
16
            'NAME': 'a2-test-%s' % os.environ.get("BRANCH_NAME", "").replace('/', '-'),
17 17
        },
18 18
    }
19 19
}
tox.ini
4 4
# and then run "tox" from this directory.
5 5

  
6 6
[tox]
7
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/authentic/
7
toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/combo/{env:BRANCH_NAME:}
8 8
envlist = coverage-dj18-{authentic,rbac}-{pg,sqlite}
9 9

  
10 10
[testenv]
......
13 13
  /bin/mv
14 14
setenv =
15 15
  AUTHENTIC2_SETTINGS_FILE=tests/settings.py
16
  BRANCH_NAME={env:BRANCH_NAME:}
16 17
  sqlite: DB_ENGINE=django.db.backends.sqlite3
17 18
  pg: DB_ENGINE=django.db.backends.postgresql_psycopg2
18
  coverage: COVERAGE=--junitxml=junit-{envname}.xml --cov-report xml --cov=src/ --cov-config .coveragerc
19
  coverage: COVERAGE=--junitxml=junit-{envname}.xml --cov-report xml --cov-report html --cov=src/ --cov-config .coveragerc
19 20
  authentic: DJANGO_SETTINGS_MODULE=authentic2.settings
20 21
  rbac: DJANGO_SETTINGS_MODULE=django_rbac.test_settings
21 22
  fast: FAST=--nomigrations
......
25 26
deps = 
26 27
  pip > 9
27 28
  dj18: django>1.8,<1.9
28
  dj19: django>1.8,<1.9
29 29
  pg: psycopg2
30 30
  coverage
31 31
  pytest-cov
......
45 45
commands =
46 46
  ./getlasso.sh
47 47
  authentic: py.test {env:FAST:} {env:COVERAGE:} {posargs:tests/ --random}
48
  rbac: py.test --nomigrations {env:COVERAGE:} {posargs:tests_rbac/}
48
  rbac: py.test {env:FAST:} {env:COVERAGE:} {posargs:tests_rbac/}
49 49
  coverage: mv coverage.xml coverage-{envname}.xml
50
  coverage-dj18-authentic-pg: mv htmlcov htmlcov-coverage-dj18-authentic-pg
51
  coverage-dj18-rbac-pg: mv htmlcov htmlcov-coverage-dj18-rbac-pg
52
  coverage-dj18-authentic-pg: ./pylint.sh src/authentic2/
50 53

  
51 54

  
52 55
[testenv:check]
53
-