forked from openwrt/openwrt
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Jenkinsfile
189 lines (163 loc) · 7.42 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
def builds = [
x86_64_us: ['device': 'x86_64', 'libc': 'musl', 'region': 'us', 'dpdk': 'false'],
x86_64_eu: ['device': 'x86_64', 'libc': 'musl', 'region': 'eu', 'dpdk': 'false'],
]
def jobs = [:] // dynamically populated later on
def credentialsId = 'buildbot'
void buildMFW(String device, String libc, String region, String startClean, String makeOptions, String dpdkFlag, String buildBranch, String toolsDir, String credentialsId) {
sshagent (credentials:[credentialsId]) {
sh "docker-compose -f ${toolsDir}/docker-compose.build.yml -p mfw_${device}_${region} build build-local-container"
sh "docker-compose -f ${toolsDir}/docker-compose.build.yml -p mfw_${device}_${region} run build-local-container ${dpdkFlag} -d ${device} -l ${libc} -r ${region} -c ${startClean} -m '${makeOptions}' -v ${buildBranch}"
}
}
void archiveMFW(String device, String region, String toolsDir, String artifactsDir) {
sh "rm -fr ${artifactsDir}"
sh "${toolsDir}/version-images.sh -d ${device} -r ${region} -o ${artifactsDir} -c -t \$(cat tmp/version.date)"
}
pipeline {
agent none
options {
disableConcurrentBuilds()
quietPeriod(60)
}
triggers {
upstream(upstreamProjects:"packetd/${env.BRANCH_NAME}, reportd/${env.BRANCH_NAME}, restd/${env.BRANCH_NAME}, sync-settings/${env.BRANCH_NAME}, classd/${env.BRANCH_NAME}, bctid/${env.BRANCH_NAME}, feeds/${env.BRANCH_NAME}, admin/${env.BRANCH_NAME}, mfw_ui/${env.BRANCH_NAME}, mfw_build/${env.BRANCH_NAME}, bpfgen/${env.BRANCH_NAME}, client-license-service/${env.BRANCH_NAME}, support-diagnostics/${env.BRANCH_NAME}, discoverd/${env.BRANCH_NAME}, wan-utils/${env.BRANCH_NAME}",
threshold: hudson.model.Result.SUCCESS)
}
parameters {
string(name:'buildBranch', defaultValue:env.BRANCH_NAME, description:'branch to use for feeds.git and mfw_build.git')
choice(name:'startClean', choices:['false', 'true'], description:'start clean')
choice(name:'onlyBuildUS', choices:['true', 'false'], description:'build only US images (no EU or other regions)')
string(name:'makeOptions', defaultValue:'-j32', description:'options passed directly to make')
}
stages {
stage('Build') {
steps {
script {
builds.each { build ->
def myDevice = build.value.device
def myRegion = build.value.region
def libc = build.value.libc
def jobName = build.key
def option = ""
def dpdkFlag = ""
if (myRegion != 'us' && onlyBuildUS == 'true') {
return
}
echo "Adding job ${build.key}"
jobs[build.key] = {
node('mfw') {
stage(jobName) {
def artifactsDir = "tmp/artifacts"
// default values for US build
def buildDir = "${env.HOME}/build-mfw-${buildBranch}-${myDevice}"
def toolsDir = "${env.HOME}/tools-mfw-${buildBranch}-${myDevice}"
if (myRegion != 'us') {
buildDir = buildDir + "-" + myRegion
toolsDir = toolsDir + "-" + myRegion
}
if (build.value.dpdk == 'true') {
dpdkFlag = "--with-dpdk"
option = "dpdk"
buildDir = buildDir + "-dpdk"
toolsDir = toolsDir + "-dpdk"
artifactsDir = artifactsDir + "/dpdk"
}
if (buildBranch =~ /^mfw\+owrt/) {
// force master
branch = 'master'
} else {
branch = buildBranch
}
echo "Building ${build.key} with branch ${branch}"
dir(toolsDir) {
git url:"[email protected]:untangle/mfw_build", branch:branch, credentialsId:credentialsId
}
dir(buildDir) {
checkout scm
buildMFW(myDevice, libc, myRegion, startClean, makeOptions, dpdkFlag, branch, toolsDir, credentialsId)
if (myDevice == 'x86_64' && myRegion == 'us' && build.value.dpdk == 'false') {
stash(name:"rootfs-${myDevice}", includes:"bin/targets/**/*generic-rootfs.tar.gz")
}
archiveMFW(myDevice, myRegion, toolsDir, "${env.WORKSPACE}/${artifactsDir}")
}
archiveArtifacts artifacts:"${artifactsDir}/**/*", fingerprint:true
}
}
} // jobs
} // for loop
parallel jobs
} // script
} // steps
post {
changed {
script {
// set result before pipeline ends, so emailer sees it
currentBuild.result = currentBuild.currentResult
}
emailext(to:'[email protected]', subject:"${env.JOB_NAME} #${env.BUILD_NUMBER}: ${currentBuild.result}", body:"${env.BUILD_URL}")
slackSend(channel:"#team_engineering", message:"${env.JOB_NAME} #${env.BUILD_NUMBER}: ${currentBuild.result} at ${env.BUILD_URL}")
}
}
} // stage
stage('Test') {
parallel {
stage('Test x86_64') {
agent { label 'mfw' }
environment {
device = 'x86_64'
toolsDir = "${env.HOME}/tools-mfw-${buildBranch}-${device}"
rootfsTarballName = 'mfw-x86-64-generic-rootfs.tar.gz'
rootfsTarballPath = "bin/targets/x86/64/${rootfsTarballName}"
dockerfile = "${toolsDir}/docker-compose.test.yml"
}
stages {
stage('Prep x86_64') {
steps {
script {
if (buildBranch =~ /^mfw\+owrt/) {
// force master
branch = 'master'
} else {
branch = buildBranch
}
dir(toolsDir) {
git url:"[email protected]:untangle/mfw_build", branch:branch, credentialsId:credentialsId
}
unstash(name:"rootfs-${device}")
sh("test -f ${rootfsTarballPath}")
sh("mv -f ${rootfsTarballPath} ${toolsDir}")
}
}
}
stage('TCP services') {
steps {
dir('mfw') {
script {
try {
sh("docker-compose -f ${dockerfile} build --build-arg ROOTFS_TARBALL=${rootfsTarballName} mfw")
sh("docker-compose -f ${dockerfile} up --abort-on-container-exit --exit-code-from test")
} catch (exc) {
currentBuild.result = 'UNSTABLE'
unstable('TCP services test failed')
}
}
}
}
}
} // stages
} // stage
} // parallel
post {
changed {
script {
// set result before pipeline ends, so emailer sees it
currentBuild.result = currentBuild.currentResult
}
emailext(to:'[email protected]', subject:"${env.JOB_NAME} #${env.BUILD_NUMBER}: ${currentBuild.result}", body:"${env.BUILD_URL}")
slackSend(channel:"#team_engineering", message:"${env.JOB_NAME} #${env.BUILD_NUMBER}: ${currentBuild.result} at ${env.BUILD_URL}")
}
}
} // stage Test
} // stages
} // pipeline