Jenkinsfile 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. // Licensed to the Apache Software Foundation (ASF) under one
  2. // or more contributor license agreements. See the NOTICE file
  3. // distributed with this work for additional information
  4. // regarding copyright ownership. The ASF licenses this file
  5. // to you under the Apache License, Version 2.0 (the
  6. // "License"); you may not use this file except in compliance
  7. // with the License. You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing,
  12. // software distributed under the License is distributed on an
  13. // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. // KIND, either express or implied. See the License for the
  15. // specific language governing permissions and limitations
  16. // under the License.
  17. def getGithubCreds() {
  18. return [usernamePassword(credentialsId: 'apache-hadoop-at-github.com',
  19. passwordVariable: 'GITHUB_TOKEN',
  20. usernameVariable: 'GITHUB_USER')]
  21. }
  22. // Publish JUnit results only if there are XML files under surefire-reports
  23. def publishJUnitResults() {
  24. def findCmdExitCode = sh script: "find ${SOURCEDIR} -wholename */target/surefire-reports/*.xml | egrep .", returnStatus: true
  25. boolean surefireReportsExist = findCmdExitCode == 0
  26. if (surefireReportsExist) {
  27. echo "XML files found under surefire-reports, running junit"
  28. // The path should be relative to WORKSPACE for the junit.
  29. SRC = "${SOURCEDIR}/**/target/surefire-reports/*.xml".replace("$WORKSPACE/","")
  30. try {
  31. junit "${SRC}"
  32. } catch(e) {
  33. echo 'junit processing: ' + e.toString()
  34. }
  35. } else {
  36. echo "No XML files found under surefire-reports, skipping junit"
  37. }
  38. }
  39. pipeline {
  40. agent {
  41. label 'Hadoop'
  42. }
  43. options {
  44. buildDiscarder(logRotator(numToKeepStr: '5'))
  45. timeout (time: 48, unit: 'HOURS')
  46. timestamps()
  47. checkoutToSubdirectory('src')
  48. }
  49. environment {
  50. YETUS='yetus'
  51. // Branch or tag name. Yetus release tags are 'rel/X.Y.Z'
  52. YETUS_VERSION='rel/0.14.0'
  53. }
  54. parameters {
  55. string(name: 'JIRA_ISSUE_KEY',
  56. defaultValue: '',
  57. description: 'The JIRA issue that has a patch needing pre-commit testing. Example: HADOOP-1234')
  58. }
  59. stages {
  60. stage ('install yetus') {
  61. steps {
  62. dir("${WORKSPACE}/${YETUS}") {
  63. checkout([
  64. $class: 'GitSCM',
  65. branches: [[name: "${env.YETUS_VERSION}"]],
  66. userRemoteConfigs: [[ url: 'https://github.com/apache/yetus.git']]]
  67. )
  68. }
  69. }
  70. }
  71. // Setup codebase so that each platform's build happens in its own exclusive copy of the
  72. // codebase.
  73. // Primarily because YETUS messes up the git branch information and affects the subsequent
  74. // optional stages after the first one.
  75. stage ('setup sources') {
  76. steps {
  77. dir("${WORKSPACE}/centos-7") {
  78. sh '''#!/usr/bin/env bash
  79. cp -Rp ${WORKSPACE}/src ${WORKSPACE}/centos-7
  80. '''
  81. }
  82. dir("${WORKSPACE}/centos-8") {
  83. sh '''#!/usr/bin/env bash
  84. cp -Rp ${WORKSPACE}/src ${WORKSPACE}/centos-8
  85. '''
  86. }
  87. dir("${WORKSPACE}/debian-10") {
  88. sh '''#!/usr/bin/env bash
  89. cp -Rp ${WORKSPACE}/src ${WORKSPACE}/debian-10
  90. '''
  91. }
  92. dir("${WORKSPACE}/ubuntu-focal") {
  93. sh '''#!/usr/bin/env bash
  94. cp -Rp ${WORKSPACE}/src ${WORKSPACE}/ubuntu-focal
  95. '''
  96. }
  97. }
  98. }
  99. // This is an optional stage which runs only when there's a change in
  100. // C++/C++ build/platform.
  101. // This stage serves as a means of cross platform validation, which is
  102. // really needed to ensure that any C++ related/platform change doesn't
  103. // break the Hadoop build on Centos 7.
  104. stage ('precommit-run Centos 7') {
  105. environment {
  106. SOURCEDIR = "${WORKSPACE}/centos-7/src"
  107. PATCHDIR = "${WORKSPACE}/centos-7/out"
  108. DOCKERFILE = "${SOURCEDIR}/dev-support/docker/Dockerfile_centos_7"
  109. IS_OPTIONAL = 1
  110. }
  111. steps {
  112. withCredentials(getGithubCreds()) {
  113. sh '''#!/usr/bin/env bash
  114. chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
  115. "${SOURCEDIR}/dev-support/jenkins.sh" run_ci
  116. '''
  117. }
  118. }
  119. post {
  120. // Since this is an optional platform, we want to copy the artifacts
  121. // and archive it only if the build fails, to help with debugging.
  122. failure {
  123. sh '''#!/usr/bin/env bash
  124. cp -Rp "${WORKSPACE}/centos-7/out" "${WORKSPACE}"
  125. '''
  126. archiveArtifacts "out/**"
  127. }
  128. cleanup() {
  129. script {
  130. sh '''#!/usr/bin/env bash
  131. chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
  132. "${SOURCEDIR}/dev-support/jenkins.sh" cleanup_ci_proc
  133. '''
  134. }
  135. }
  136. }
  137. }
  138. // This is an optional stage which runs only when there's a change in
  139. // C++/C++ build/platform.
  140. // This stage serves as a means of cross platform validation, which is
  141. // really needed to ensure that any C++ related/platform change doesn't
  142. // break the Hadoop build on Centos 8.
  143. stage ('precommit-run Centos 8') {
  144. environment {
  145. SOURCEDIR = "${WORKSPACE}/centos-8/src"
  146. PATCHDIR = "${WORKSPACE}/centos-8/out"
  147. DOCKERFILE = "${SOURCEDIR}/dev-support/docker/Dockerfile_centos_8"
  148. IS_OPTIONAL = 1
  149. }
  150. steps {
  151. withCredentials(getGithubCreds()) {
  152. sh '''#!/usr/bin/env bash
  153. chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
  154. "${SOURCEDIR}/dev-support/jenkins.sh" run_ci
  155. '''
  156. }
  157. }
  158. post {
  159. // Since this is an optional platform, we want to copy the artifacts
  160. // and archive it only if the build fails, to help with debugging.
  161. failure {
  162. sh '''#!/usr/bin/env bash
  163. cp -Rp "${WORKSPACE}/centos-8/out" "${WORKSPACE}"
  164. '''
  165. archiveArtifacts "out/**"
  166. }
  167. cleanup() {
  168. script {
  169. sh '''#!/usr/bin/env bash
  170. chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
  171. "${SOURCEDIR}/dev-support/jenkins.sh" cleanup_ci_proc
  172. '''
  173. }
  174. }
  175. }
  176. }
  177. // This is an optional stage which runs only when there's a change in
  178. // C++/C++ build/platform.
  179. // This stage serves as a means of cross platform validation, which is
  180. // really needed to ensure that any C++ related/platform change doesn't
  181. // break the Hadoop build on Debian 10.
  182. stage ('precommit-run Debian 10') {
  183. environment {
  184. SOURCEDIR = "${WORKSPACE}/debian-10/src"
  185. PATCHDIR = "${WORKSPACE}/debian-10/out"
  186. DOCKERFILE = "${SOURCEDIR}/dev-support/docker/Dockerfile_debian_10"
  187. IS_OPTIONAL = 1
  188. }
  189. steps {
  190. withCredentials(getGithubCreds()) {
  191. sh '''#!/usr/bin/env bash
  192. chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
  193. "${SOURCEDIR}/dev-support/jenkins.sh" run_ci
  194. '''
  195. }
  196. }
  197. post {
  198. // Since this is an optional platform, we want to copy the artifacts
  199. // and archive it only if the build fails, to help with debugging.
  200. failure {
  201. sh '''#!/usr/bin/env bash
  202. cp -Rp "${WORKSPACE}/debian-10/out" "${WORKSPACE}"
  203. '''
  204. archiveArtifacts "out/**"
  205. }
  206. cleanup() {
  207. script {
  208. sh '''#!/usr/bin/env bash
  209. chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
  210. "${SOURCEDIR}/dev-support/jenkins.sh" cleanup_ci_proc
  211. '''
  212. }
  213. }
  214. }
  215. }
  216. // We want to use Ubuntu Focal as our main CI and thus, this stage
  217. // isn't optional (runs for all the PRs).
  218. stage ('precommit-run Ubuntu focal') {
  219. environment {
  220. SOURCEDIR = "${WORKSPACE}/ubuntu-focal/src"
  221. PATCHDIR = "${WORKSPACE}/ubuntu-focal/out"
  222. DOCKERFILE = "${SOURCEDIR}/dev-support/docker/Dockerfile"
  223. IS_OPTIONAL = 0
  224. }
  225. steps {
  226. withCredentials(getGithubCreds()) {
  227. sh '''#!/usr/bin/env bash
  228. chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
  229. "${SOURCEDIR}/dev-support/jenkins.sh" run_ci
  230. '''
  231. }
  232. }
  233. post {
  234. always {
  235. script {
  236. // Publish status if it was missed (YETUS-1059)
  237. withCredentials(
  238. [usernamePassword(credentialsId: '683f5dcf-5552-4b28-9fb1-6a6b77cf53dd',
  239. passwordVariable: 'GITHUB_TOKEN',
  240. usernameVariable: 'GITHUB_USER')]) {
  241. sh '''#!/usr/bin/env bash
  242. # Copy the artifacts of Ubuntu focal build to workspace
  243. cp -Rp "${WORKSPACE}/ubuntu-focal/out" "${WORKSPACE}"
  244. # Send Github status
  245. chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
  246. "${SOURCEDIR}/dev-support/jenkins.sh" github_status_recovery
  247. '''
  248. }
  249. // YETUS output
  250. archiveArtifacts "out/**"
  251. // Publish the HTML report so that it can be looked at
  252. // Has to be relative to WORKSPACE.
  253. publishHTML (target: [
  254. allowMissing: true,
  255. keepAll: true,
  256. alwaysLinkToLastBuild: true,
  257. // Has to be relative to WORKSPACE
  258. reportDir: "out",
  259. reportFiles: 'report.html',
  260. reportName: 'Yetus Report'
  261. ])
  262. publishJUnitResults()
  263. }
  264. }
  265. cleanup() {
  266. script {
  267. sh '''#!/usr/bin/env bash
  268. chmod u+x "${SOURCEDIR}/dev-support/jenkins.sh"
  269. "${SOURCEDIR}/dev-support/jenkins.sh" cleanup_ci_proc
  270. '''
  271. }
  272. }
  273. }
  274. }
  275. }
  276. post {
  277. // Jenkins pipeline jobs fill slaves on PRs without this :(
  278. cleanup() {
  279. script {
  280. sh '''#!/usr/bin/env bash
  281. # See HADOOP-13951
  282. chmod -R u+rxw "${WORKSPACE}"
  283. '''
  284. deleteDir()
  285. }
  286. }
  287. }
  288. }