-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathJenkinsfile
79 lines (77 loc) · 2.97 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env groovy
import hudson.plugins.cobertura.targets.CoverageMetric;
pipeline {
agent any
stages {
stage('Setup') {
steps {
sh 'eval "$(pyenv init -)"'
sh 'pyenv install -s ${PY26_VER}'
sh 'pyenv install -s ${PY27_VER}'
sh 'pyenv install -s ${PYPY2_VER}'
sh 'pyenv local ${PY26_VER} ${PY27_VER} ${PYPY2_VER}'
sh 'pip2 install --upgrade tox'
}
}
stage('Unit test') {
steps {
sh 'tox -e py26,py27,pypy --recreate -- --junitxml=results/\'$TOXENV\'-results.xml'
}
}
stage('Linter') {
steps {
sh 'tox --recreate -e flake8 -- --output-file=flake8.txt'
}
}
stage('Coverage') {
steps {
sh 'tox -e py27 --recreate -- --cov=abusehelper --cov-report term-missing --cov-report xml:results/cov.xml'
}
}
}
post {
success {
script {
percentage = manager.build.getAction(hudson.plugins.cobertura.CoberturaBuildAction.class).getResults()[CoverageMetric.LINE].getPercentageFloat();
if (percentage > 80) {
bgcolour = "greenyellow";
}
else if (percentage > 50) {
bgcolour = "yellow";
}
else {
bgcolour = "red";
}
textpercentage = "Coverage: " + Math.round(percentage).toString() + "%";
manager.addShortText(textpercentage, "black", bgcolour, "2px", "black");
previousResult = currentBuild.getPreviousBuild()?.getResult().toString()
if (previousResult != "SUCCESS" && previousResult != "null") {
emailext body: '''${SCRIPT, template="abusesa-html.template"}''',
recipientProviders: [[$class: 'DevelopersRecipientProvider'],
[$class: 'CulpritsRecipientProvider']],
replyTo: '[email protected]',
subject: '[Jenkins]: ${JOB_NAME} ${BUILD_DISPLAY_NAME} - FIXED',
to: '[email protected]',
mimeType: 'text/html'
}
}
}
failure {
emailext body: '''${SCRIPT, template="abusesa-html.template"}''',
recipientProviders: [[$class: 'DevelopersRecipientProvider'],
[$class: 'CulpritsRecipientProvider']],
replyTo: '[email protected]',
subject: '[Jenkins]: ${JOB_NAME} ${BUILD_DISPLAY_NAME} - FAILURE',
to: '[email protected]',
mimeType: 'text/html'
}
always {
sh 'if [[ -s flake8.txt ]]; then mv flake8.txt results/flake8.log; fi'
sh 'pyenv local --unset'
archiveArtifacts artifacts: 'results/*'
junit '**/results/*-results.xml'
step([$class: 'CoberturaPublisher', autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/results/cov.xml', failNoReports: false, failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false])
deleteDir()
}
}
}