forked from danos/vyatta-dataplane
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
179 lines (162 loc) · 5.27 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
#!groovy
// 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 = 'DANOS: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 all_tests sanitizer'
}
options {
timeout(time: 60, unit: 'MINUTES')
checkoutToSubdirectory("vyatta-dataplane")
quietPeriod(90) // Wait 90 seconds in case there are more SCM pushes/PR merges coming
}
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('vyatta-dataplane') {
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('cppcheck Static Analysis') {
when {expression { env.CHANGE_ID == null }} // Not when this is a Pull Request
environment {
extra_cppcheck_parameters = '--xml-version=2 --error-exitcode=0'
}
steps {
dir('vyatta-dataplane') {
sh "./scripts/cppcheck_wrapper.sh 2> ${WORKSPACE}/cppcheck.xml"
}
// TODO: Currently this doesn't cause a failure
// TODO: Fail if the number of cppcheck errors is above some threshold.
// TODO: Better yet would for there to be none and then remove
// --error-exitcode=0 above so that it fails on any reported error.
sh 'cppcheck-htmlreport --title="Vyatta Dataplane" --file=cppcheck.xml --report-dir=cppcheck_reports --source-dir=vyatta-dataplane'
}
post {
success {
publishHTML target: [
allowMissing: false,
alwaysLinkToLastBuild: true,
keepAll: true,
reportDir: 'cppcheck_reports',
reportFiles: 'index.html',
reportTitles: 'cppcheck Static Analysis',
reportName: 'cppcheck Static Analysis Report'
]
}
}
}
stage('Code Stats') {
when {expression { env.CHANGE_ID == null }} // Not when this is a Pull Request
steps {
sh 'sloccount --duplicates --wide --details vyatta-dataplane > sloccount.sc'
sloccountPublish pattern: '**/sloccount.sc'
}
}
stage('checkpatch') {
when {
allOf {
// Only if this is a Pull Request
expression { env.CHANGE_ID != null }
expression { env.CHANGE_TARGET != null }
}
}
steps {
dir('vyatta-dataplane') {
//TODO: Path to checkpatch.pl should not be hardcoded!
sh "PATH=~/linux-vyatta/scripts:$PATH ./scripts/checkpatch_wrapper.sh upstream/${env.CHANGE_TARGET} origin/${env.BRANCH_NAME}"
}
}
}
stage('gitlint') {
when {
allOf {
// Only if this is a Pull Request
expression { env.CHANGE_ID != null }
expression { env.CHANGE_TARGET != null }
}
}
agent {
docker { image 'jorisroovers/gitlint'
args '--entrypoint=""'
reuseNode true
}
}
steps {
dir('vyatta-dataplane') {
sh "gitlint --commits upstream/${env.CHANGE_TARGET}..origin/${env.BRANCH_NAME}"
}
}
}
} // stages
post {
always {
sh 'rm -f *.deb'
sh "osc chroot --wipe --force --root ${env.OSC_BUILD_ROOT}"
deleteDir()
}
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()]
)
}
}
}