forked from GOVCERT-LU/eml_parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.jenkinsfile
201 lines (178 loc) · 6.31 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
pipeline {
agent any
options {
ansiColor('xterm')
timestamps()
timeout(time: 1, unit: 'HOURS')
// Keep the 10 most recent builds
buildDiscarder(logRotator(numToKeepStr: '10'))
gitLabConnection('Gitlab')
gitlabBuilds(builds: ['Lint', 'Linters', 'Test results', 'Coverage'])
}
environment {
Python = "3.7"
}
stages {
stage ("Code pull"){
steps{
// make sure any earlier build is canceled
milestone label: '', ordinal: Integer.parseInt(env.BUILD_ID) - 1
milestone label: '', ordinal: Integer.parseInt(env.BUILD_ID)
checkout scm
sh 'cp /etc/ssl/certs/govcertCA.pem .'
}
}
stage('Lint') {
when {
not {
tag pattern: "v\\d+\\.\\d+\\.\\d+", comparator: "REGEXP"
}
}
steps {
gitlabCommitStatus('Lint') {
script {
try {
docker.image('python:${Python}').inside("--tmpfs /.local --tmpfs /.cache") {
sh '''
export
export HTTP_PROXY="${PROXY}"
export HTTPS_PROXY="${PROXY}"
export NO_PROXY=localhost,127.0.0.1,.govcert.etat.lu
export HOME=${PWD}
export PYTHONUSERBASE=.py_${Python}
python -m venv .py_${Python}
source .py_${Python}/bin/activate
pip install -U pip tox
tox
'''
}
} catch (err) {
}
}
}
}
}
stage('Analysis') {
when {
not {
tag pattern: "v\\d+\\.\\d+\\.\\d+", comparator: "REGEXP"
}
}
parallel {
stage('Linters') {
steps {
gitlabCommitStatus('Linters') {
recordIssues(tools: [pyLint(pattern: "pylint_${Python}.log",
id: "Python_${Python}_pylint",
name: "Py-${Python} Pylint"),
myPy(pattern: "mypy_${Python}.log",
id: "Python_${Python}_mypy",
name: "Py-${Python} MyPy"),
flake8(pattern: "flake8_${Python}.log",
id: "Python_${Python}_flake8",
name: "Py-${Python} Flake8")
])
}
}
}
stage('Test results') {
steps {
gitlabCommitStatus('Test results') {
xunit (
thresholds: [ skipped(failureThreshold: '0'), failed(failureThreshold: '0') ],
tools: [ JUnit(pattern: "**/junit_${Python}.xml") ]
)
}
}
}
stage('Coverage') {
steps {
gitlabCommitStatus('Coverage') {
cobertura(autoUpdateHealth: false,
autoUpdateStability: false,
coberturaReportFile: "**/coverage_${Python}.xml",
failUnhealthy: false,
failUnstable: false,
maxNumberOfBuilds: 20,
onlyStable: false,
sourceEncoding: 'ASCII',
zoomCoverageChart: false
)
}
}
}
}
}
stage('Build package') {
when {
allOf {
tag pattern: "v\\d+\\.\\d+\\.\\d+", comparator: "REGEXP"
expression {
currentBuild.result == null || currentBuild.result == 'SUCCESS'
}
}
}
steps {
script {
try {
docker.image('python:${Python}').inside("--tmpfs /.local --tmpfs /.cache") {
sh '''
export
export HTTP_PROXY="${PROXY}"
export HTTPS_PROXY="${PROXY}"
export NO_PROXY=localhost,127.0.0.1,.govcert.etat.lu
export HOME=${PWD}
export PYTHONUSERBASE=.py_${Python}
mkdir -p dist
pip wheel --no-deps -w dist/ .
'''
}
} catch (err) {
}
}
}
post {
always {
withCredentials([usernamePassword(credentialsId: 'apps1-pypiserver-jenkins', usernameVariable: 'TWINE_USERNAME', passwordVariable: 'TWINE_PASSWORD')]) {
script {
try {
docker.image('python:${Python}').inside("--tmpfs /.local --tmpfs /.cache") {
sh '''cat govcertCA.pem /etc/ssl/certs/ca-certificates.crt > ssl_cas.pem
export
export HTTP_PROXY="${PROXY}"
export HTTPS_PROXY="${PROXY}"
export NO_PROXY=localhost,127.0.0.1,.govcert.etat.lu
export HOME=${PWD}
export PIP_CERT=${PWD}/ssl_cas.pem
export PATH=${PATH}:${PWD}/.local/bin
export TWINE_CERT=${PWD}/ssl_cas.pem
pip install -U twine
twine upload dist/*.whl
'''
}
} catch (err) {
}
}
updateGitlabCommitStatus name: 'Lint', state: 'canceled'
updateGitlabCommitStatus name: 'Linters', state: 'canceled'
updateGitlabCommitStatus name: 'Test results', state: 'canceled'
updateGitlabCommitStatus name: 'Coverage', state: 'canceled'
}
}
}
}
}
post {
failure {
script {
def commitemail = sh(script:'cd ${WORKSPACE}; git log -1 --pretty=format:"%ce"', returnStdout:true).trim()
emailext body: "${currentBuild.currentResult}: Job ${env.JOB_NAME} build ${env.BUILD_NUMBER}\n More info at: ${env.BUILD_URL}",
to: commitemail, subject: "Jenkins Build ${currentBuild.currentResult}: Job ${env.JOB_NAME}"
}
updateGitlabCommitStatus name: 'build', state: 'failed'
}
success {
updateGitlabCommitStatus name: 'build', state: 'success'
}
}
}