forked from danos/vplane-config-npf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
226 lines (204 loc) · 7.65 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#!groovy
/*
* Copyright (c) 2020, AT&T Intellectual Property.
* All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-only
*/
/* SRC_DIR is where the project will be checked out,
* and where all the steps will be run.
*/
def SRC_DIR="vplane-config-npf"
// Pull Request builds might fail due to missing diffs: https://issues.jenkins-ci.org/browse/JENKINS-45997
// Pull Request builds relationship to their targets branch: https://issues.jenkins-ci.org/browse/JENKINS-37491
@NonCPS
def cancelPreviousBuilds() {
def jobName = env.JOB_NAME
def buildNumber = env.BUILD_NUMBER.toInteger()
/* Get job name */
def currentJob = Jenkins.instance.getItemByFullName(jobName)
/* Iterating over the builds for specific job */
for (def build : currentJob.builds) {
/* If there is a build that is currently running and it's not current build */
if (build.isBuilding() && build.number.toInteger() != buildNumber) {
/* Than stopping it */
build.doStop()
}
}
}
pipeline {
agent any
environment {
OBS_TARGET_PROJECT = 'Vyatta:Master'
OBS_TARGET_REPO = 'standard'
OBS_TARGET_ARCH = 'x86_64'
// # Replace : with _ in project name, as osc-buildpkg does
OSC_BUILD_ROOT = "${WORKSPACE}" + '/build-root/' + "${env.OBS_TARGET_PROJECT.replace(':','_')}" + '-' + "${env.OBS_TARGET_REPO}" + '-' + "${OBS_TARGET_ARCH}"
DH_VERBOSE = 1
DH_QUIET = 0
DEB_BUILD_OPTIONS = 'verbose'
// CHANGE_TARGET is set for PRs.
// When CHANGE_TARGET is not set it's a regular build so we use BRANCH_NAME.
REF_BRANCH = "${env.CHANGE_TARGET != null ? env.CHANGE_TARGET : env.BRANCH_NAME}"
SRC_DIR = "${SRC_DIR}"
}
options {
timeout(time: 180, unit: 'MINUTES') // Hopefully maximum even when Valgrind is included!
checkoutToSubdirectory("${SRC_DIR}")
quietPeriod(30) // Wait in case there are more SCM pushes/PR merges coming
ansiColor('xterm')
timestamps()
}
stages {
// A work around, until this feature is implemented: https://issues.jenkins-ci.org/browse/JENKINS-47503
stage('Cancel older builds') { steps { script {
cancelPreviousBuilds()
}}}
stage('OSC config') {
steps {
sh 'printenv'
// Build scripts with tasks to perform in the chroot
sh """
cat <<EOF > osc-buildpackage_buildscript_default
export BUILD_ID=\"${BUILD_ID}\"
export JENKINS_NODE_COOKIE=\"${JENKINS_NODE_COOKIE}\"
dpkg-buildpackage -jauto -us -uc -b
EOF
"""
}
}
// Workspace specific chroot location used instead of /var/tmp
// Allows parallel builds between jobs, but not between stages in a single job
// TODO: Enhance osc-buildpkg to support parallel builds from the same pkg_srcdir
// TODO: probably by allowing it to accept a .conf file from a location other than pkg_srcdir
stage('OSC Build') {
steps {
dir("${SRC_DIR}") {
sh """
cat <<EOF > .osc-buildpackage.conf
OSC_BUILDPACKAGE_TMP=\"${WORKSPACE}\"
OSC_BUILDPACKAGE_BUILDSCRIPT=\"${WORKSPACE}/osc-buildpackage_buildscript_default\"
EOF
"""
sh "osc-buildpkg -v -g -T -P ${env.OBS_TARGET_PROJECT} ${env.OBS_TARGET_REPO} -- --trust-all-projects --build-uid='caller'"
}
}
}
stage('Code Stats') {
when {expression { env.CHANGE_ID == null }} // Not when this is a Pull Request
steps {
sh 'sloccount --duplicates --wide --details ${SRC_DIR} > sloccount.sc'
sloccountPublish pattern: '**/sloccount.sc'
}
}
/* We can't do a simple
* sh "dram --username jenkins -d yang"
* because the base yang dir contains a VNF module
* and there are platform modules in another dir.
*/
stage('DRAM') {
steps {
dir("${SRC_DIR}") {
sh '''
yang=`echo yang/*.yang | sed 's@yang/vyatta-policy-pbr-bridge-v1.yang @@' | sed 's/ /,/g'`
platform=`echo platform/*.platform | sed 's/ /,/g'`
platyang=`echo platform/*.yang | sed 's/ /,/g'`
dram --username jenkins -f \$yang -P \$platform -Y \$platyang -v yang/vyatta-policy-pbr-bridge-v1.yang -s
'''
}
}
}
stage('Perlcritic') {
steps {
dir("${SRC_DIR}") {
sh script: "perlcritic --quiet --severity 5 . 2>&1 | tee perlcritic.txt", returnStatus: true
}
}
post {
always {
dir("${env.SRC_DIR}") {
recordIssues tool: perlCritic(pattern: 'perlcritic.txt'),
enabledForFailure: true,
qualityGates: [[type: 'TOTAL', threshold: 1, unstable: true]]
}
}
}
}
stage('Flake8') {
steps {
dir("${SRC_DIR}") {
sh '''
pyfiles=`find . -type f -exec file --mime-type {} \\; | grep "text/x-python" | cut -d: -f1 | cut -c3- | xargs`
python3 -m flake8 --output-file=flake8.out --count --exit-zero --exclude=.git/*,debian/* \$pyfiles
'''
}
}
post {
always {
dir("${env.SRC_DIR}") {
recordIssues tool: flake8(pattern: 'flake8.out'),
enabledForFailure: true,
referenceJobName: "DANOS/${SRC_DIR}/${env.REF_BRANCH}",
qualityGates: [[type: 'TOTAL', threshold: 22, unstable: true],
[type: 'NEW', threshold: 1, unstable: true]]
}
}
}
}
stage('Codechecks') {
when {
allOf {
// Only if this is a Pull Request
expression { env.CHANGE_ID != null }
expression { env.CHANGE_TARGET != null }
}
}
steps {
dir("${SRC_DIR}") {
sh "./codechecks upstream/${env.CHANGE_TARGET} origin/${env.BRANCH_NAME}"
}
}
}
stage('Gitlint') {
agent {
docker {
image 'jorisroovers/gitlint'
args '--entrypoint=""'
reuseNode true
}
}
when {
allOf {
// Only if this is a Pull Request
expression { env.CHANGE_ID != null }
expression { env.CHANGE_TARGET != null }
}
}
steps {
dir("${SRC_DIR}") {
sh "gitlint --commits upstream/${env.CHANGE_TARGET}..origin/${env.BRANCH_NAME}"
}
}
}
} // stages
post {
always {
sh 'rm -f *.deb' // top-level dir
sh "osc chroot --wipe --force --root ${env.OSC_BUILD_ROOT}"
deleteDir()
// Do any clean up for DRAM?
}
success {
echo 'Winning'
}
failure {
echo 'Argh... something went wrong'
emailext (
subject: "FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>FAILED: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at "<a href="${env.BUILD_URL}">${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>"</p>""",
recipientProviders: [culprits()]
)
}
}
}