Jenkinsfile 15 KB

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