Jenkinsfile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. pipeline {
  2. options {
  3. disableConcurrentBuilds()
  4. preserveStashes(buildCount: 10)
  5. timestamps()
  6. }
  7. parameters {
  8. booleanParam(name: "BUILD_ALL", defaultValue: false, description: "Build all supported platform/architecture combos. Defaults to x86/x64 only")
  9. }
  10. environment {
  11. PATH = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/home/jenkins-build/go/bin"
  12. }
  13. agent none
  14. stages {
  15. stage ("Build") {
  16. steps {
  17. script {
  18. def tasks = [:]
  19. tasks << buildStaticBinaries()
  20. tasks << buildDebianNative()
  21. tasks << buildCentosNative()
  22. parallel tasks
  23. }
  24. }
  25. }
  26. // stage ("Package Static") {
  27. // steps {
  28. // script {
  29. // parallel packageStatic()
  30. // }
  31. // }
  32. // }
  33. }
  34. }
  35. def buildStaticBinaries() {
  36. def tasks = [:]
  37. def dist = ["alpine"]
  38. def archs = []
  39. if (params.BUILD_ALL == true) {
  40. archs = ["arm64", "amd64", "i386", "armhf", "armel", "ppc64le", "s390x"]
  41. } else {
  42. archs = ["amd64", "i386"]
  43. }
  44. tasks << getTasks(dist, archs, { distro, platform ->
  45. def myNode = {
  46. node ('linux-build') {
  47. dir ("build") {
  48. checkout scm
  49. }
  50. def runtime = docker.image("ztbuild/${distro}-${platform}:latest")
  51. runtime.inside {
  52. dir("build") {
  53. def cmakeFlags = 'CMAKE_ARGS="-DBUILD_STATIC=1"'
  54. if (platform == "i386") {
  55. cmakeFlags = 'CMAKE_ARGS="-DBUILD_32BIT=1 -DBUILD_STATIC=1"'
  56. }
  57. sh "${cmakeFlags} make"
  58. dir("build") {
  59. sh "mv zerotier zerotier-static-${platform}"
  60. stash includes: 'zerotier-static-*', name: "static-${platform}"
  61. }
  62. }
  63. cleanWs deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true
  64. }
  65. }
  66. }
  67. return myNode
  68. })
  69. return tasks
  70. }
  71. def getTasks(axisDistro, axisPlatform, task) {
  72. def tasks = [:]
  73. for(int i=0; i< axisDistro.size(); i++) {
  74. def axisDistroValue = axisDistro[i]
  75. for(int j=0; j< axisPlatform.size(); j++) {
  76. def axisPlatformValue = axisPlatform[j]
  77. tasks["${axisDistroValue}/${axisPlatformValue}"] = task(axisDistroValue, axisPlatformValue)
  78. }
  79. }
  80. return tasks
  81. }
  82. def packageStatic() {
  83. def tasks = [:]
  84. def centos6 = ["centos6"]
  85. def centos6Arch = ["i386", "amd64"]
  86. tasks << getTasks(centos6, centos6Arch, { distro, arch ->
  87. def myNode = {
  88. node ('linux-build') {
  89. dir ("build") {
  90. checkout scm
  91. }
  92. def runtime = docker.image("ztbuild/${distro}-${arch}:latest")
  93. runtime.inside {
  94. dir("build") {
  95. unstash "static-${arch}"
  96. sh "mv zerotier-static-${arch} zerotier && chmod +x zerotier"
  97. sh "make redhat"
  98. sh "mkdir -p ${distro}"
  99. sh "cp -av `find ~/rpmbuild/ -type f -name \"*.rpm\"` ${distro}/"
  100. archiveArtifacts artifacts: "${distro}/*.rpm", onlyIfSuccessful: true
  101. }
  102. }
  103. cleanWs deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true
  104. }
  105. }
  106. return myNode
  107. })
  108. def centos7 = ["centos7"]
  109. def centos7Arch = ["i386"]
  110. tasks << getTasks(centos7, centos7Arch, { distro, arch ->
  111. def myNode = {
  112. node ('linux-build') {
  113. dir ("build") {
  114. checkout scm
  115. }
  116. def runtime = docker.image("ztbuild/${distro}-${arch}:latest")
  117. runtime.inside {
  118. dir("build") {
  119. unstash "static-${arch}"
  120. sh "mv zerotier-static-${arch} zerotier && chmod +x zerotier"
  121. sh "make redhat"
  122. sh "mkdir -p ${distro}"
  123. sh "cp -av `find ~/rpmbuild/ -type f -name \"*.rpm\"` ${distro}/"
  124. archiveArtifacts artifacts: "${distro}/*.rpm", onlyIfSuccessful: true
  125. }
  126. }
  127. cleanWs deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true
  128. }
  129. }
  130. return myNode
  131. })
  132. if (params.BUILD_ALL == true) {
  133. def clefos7 = ["clefos"]
  134. def clefos7Arch = ["s390x"]
  135. tasks << getTasks(clefos7, clefos7Arch, { distro, arch ->
  136. def myNode = {
  137. node ('linux-build') {
  138. dir ("build") {
  139. checkout scm
  140. }
  141. def runtime = docker.image("ztbuild/${distro}-${arch}:latest")
  142. runtime.inside {
  143. dir("build/") {
  144. unstash "static-${arch}"
  145. sh "mv zerotier-static-${arch} zerotier && chmod +x zerotier"
  146. sh "make redhat"
  147. sh "mkdir -p ${distro}"
  148. sh "cp -av `find ~/rpmbuild/ -type f -name \"*.rpm\"` ${distro}/"
  149. archiveArtifacts artifacts: "${distro}/*.rpm", onlyIfSuccessful: true
  150. }
  151. }
  152. cleanWs deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true
  153. }
  154. }
  155. return myNode
  156. })
  157. }
  158. def debianJessie = ["debian-jessie"]
  159. def debianJessieArchs = []
  160. if (params.BUILD_ALL == true) {
  161. debianJessieArch = ["armhf", "armel", "amd64", "i386"]
  162. } else {
  163. debianJessieArch = ["amd64", "i386"]
  164. }
  165. tasks << getTasks(debianJessie, debianJessieArch, { distro, arch ->
  166. def myNode = {
  167. node ('linux-build') {
  168. dir ("build") {
  169. checkout scm
  170. }
  171. def runtime = docker.image("ztbuild/${distro}-${arch}:latest")
  172. runtime.inside {
  173. sh "ls -la ."
  174. dir('build/') {
  175. sh "ls -la ."
  176. unstash "static-${arch}"
  177. sh "pwd"
  178. sh "mv zerotier-static-${arch} zerotier && chmod +x zerotier && file ./zerotier"
  179. sh "mv -f debian/rules.static debian/rules"
  180. sh "make debian"
  181. }
  182. sh "mkdir -p ${distro}"
  183. sh "mv *.deb ${distro}"
  184. archiveArtifacts artifacts: "${distro}/*.deb", onlyIfSuccessful: true
  185. }
  186. cleanWs deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true
  187. }
  188. }
  189. return myNode
  190. })
  191. def ubuntuTrusty = ["ubuntu-trusty"]
  192. def ubuntuTrustyArch = []
  193. if (params.BUILD_ALL == true) {
  194. ubuntuTrustyArch = ["i386", "amd64", "armhf", "arm64", "ppc64le"]
  195. } else {
  196. ubuntuTrustyArch = ["i386", "amd64"]
  197. }
  198. tasks << getTasks(ubuntuTrusty, ubuntuTrustyArch, { distro, arch ->
  199. def myNode = {
  200. node ('linux-build') {
  201. dir ("build") {
  202. checkout scm
  203. }
  204. def runtime = docker.image("ztbuild/${distro}-${arch}:latest")
  205. runtime.inside {
  206. sh "ls -la ."
  207. dir('build/') {
  208. sh "ls -la ."
  209. unstash "static-${arch}"
  210. sh "pwd"
  211. sh "mv zerotier-static-${arch} zerotier && chmod +x zerotier && file ./zerotier"
  212. sh "mv -f debian/rules.static debian/rules"
  213. sh "make debian"
  214. }
  215. sh "mkdir -p ${distro}"
  216. sh "mv *.deb ${distro}"
  217. archiveArtifacts artifacts: "${distro}/*.deb", onlyIfSuccessful: true
  218. }
  219. cleanWs deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true
  220. }
  221. }
  222. return myNode
  223. })
  224. def debianWheezy = ["debian-wheezy"]
  225. def debianWheezyArchs = []
  226. if (params.BUILD_ALL == true) {
  227. debianWheezyArchs = ["armhf", "armel", "amd64", "i386"]
  228. } else {
  229. debianWheezyArchs = ["amd64", "i386"]
  230. }
  231. tasks << getTasks(debianJessie, debianJessieArch, { distro, arch ->
  232. def myNode = {
  233. node ('linux-build') {
  234. dir ("build") {
  235. checkout scm
  236. }
  237. def runtime = docker.image("ztbuild/${distro}-${arch}:latest")
  238. runtime.inside {
  239. dir('build/') {
  240. unstash "static-${arch}"
  241. sh "mv zerotier-static-${arch} zerotier && chmod +x zerotier && file ./zerotier"
  242. sh "mv -f debian/rules.wheezy.static debian/rules"
  243. sh "mv -f debian/control.wheezy debian/control"
  244. sh "make debian"
  245. }
  246. sh "mkdir -p ${distro}"
  247. sh "mv *.deb ${distro}"
  248. archiveArtifacts artifacts: "${distro}/*.deb", onlyIfSuccessful: true
  249. }
  250. cleanWs deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true
  251. }
  252. }
  253. return myNode
  254. })
  255. return tasks
  256. }
  257. def buildDebianNative() {
  258. def tasks = [:]
  259. def buster = ["debian-buster", "debian-stretch", "debian-bullseye", "debian-sid"]
  260. def busterArchs = []
  261. if (params.BUILD_ALL) {
  262. busterArchs = ["s390x", "ppc64le", "i386", "armhf", "armel", "arm64", "amd64"]
  263. } else {
  264. busterArchs = ["amd64", "i386"]
  265. }
  266. def build = { distro, arch ->
  267. def myNode = {
  268. node ('linux-build') {
  269. dir ("build") {
  270. checkout scm
  271. }
  272. def runtime = docker.image("ztbuild/${distro}-${arch}:latest")
  273. runtime.inside {
  274. def cmakeFlags = ""
  275. if (arch == "i386") {
  276. cmakeFlags = 'CMAKE_ARGS="-DBUILD_32BIT=1"'
  277. }
  278. sh 'whoami'
  279. dir("build") {
  280. sh "${cmakeFlags} make -j4"
  281. }
  282. // sh "mkdir -p ${distro}"
  283. // sh "mv *.deb ${distro}"
  284. // archiveArtifacts artifacts: "${distro}/*.deb", onlyIfSuccessful: true
  285. cleanWs deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true
  286. }
  287. }
  288. }
  289. return myNode
  290. }
  291. tasks << getTasks(buster, busterArchs, build)
  292. // bash is broken when running under QEMU-s390x on Xenial
  293. def xenial = ["ubuntu-xenial"]
  294. def xenialArchs = []
  295. if (params.BUILD_ALL == true) {
  296. xenialArchs = ["i386", "amd64", "armhf", "arm64", "ppc64le"]
  297. } else {
  298. xenialArchs = ["i386", "amd64"]
  299. }
  300. tasks << getTasks(xenial, xenialArchs, build)
  301. def ubuntu = ["ubuntu-bionic", "ubuntu-eoan"]
  302. def ubuntuArchs = []
  303. if (params.BUILD_ALL == true) {
  304. ubuntuArchs = ["i386", "amd64", "armhf", "arm64", "ppc64le", "s390x"]
  305. } else {
  306. ubuntuArchs = ["i386", "amd64"]
  307. }
  308. tasks << getTasks(ubuntu, ubuntuArchs, build)
  309. def ubuntuFocal = ["ubuntu-focal"]
  310. def ubuntuFocalArchs = []
  311. if (params.BUILD_ALL == true) {
  312. ubuntuFocalArchs = ["amd64", "armhf", "arm64", "ppc64le", "s390x"]
  313. } else {
  314. ubuntuFocalArchs = ["amd64"]
  315. }
  316. tasks << getTasks(ubuntuFocal, ubuntuFocalArchs, build)
  317. def kali = ["kali-rolling"]
  318. def kaliArchs = ["amd64"]
  319. tasks << getTasks(kali, kaliArchs, build)
  320. return tasks
  321. }
  322. def buildCentosNative() {
  323. def tasks = [:]
  324. def build = { distro, arch ->
  325. def myNode = {
  326. node ('linux-build') {
  327. dir ("build") {
  328. checkout scm
  329. }
  330. def runtime = docker.image("ztbuild/${distro}-${arch}:latest")
  331. runtime.inside {
  332. dir("build") {
  333. if (distro == 'centos7' && arch == 'amd64') {
  334. sh 'source scl_source enable devtoolset-8 llvm-toolset-7 && make'
  335. } else {
  336. sh 'make'
  337. }
  338. // sh 'make redhat'
  339. // sh "mkdir -p ${distro}"
  340. // sh "cp -av `find ~/rpmbuild/ -type f -name \"*.rpm\"` ${distro}/"
  341. // archiveArtifacts artifacts: "${distro}/*.rpm", onlyIfSuccessful: true
  342. }
  343. cleanWs deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true
  344. }
  345. }
  346. }
  347. return myNode
  348. }
  349. def centos8 = ["centos8"]
  350. def centos8Archs = []
  351. if (params.BUILD_ALL == true) {
  352. centos8Archs = ["amd64", "arm64", "ppc64le"]
  353. } else {
  354. centos8Archs = ["amd64"]
  355. }
  356. tasks << getTasks(centos8, centos8Archs, build)
  357. def centos7 = ["centos7"]
  358. def centos7Archs = ["amd64"]
  359. tasks << getTasks(centos7, centos7Archs, build)
  360. return tasks
  361. }