Jenkinsfile 12 KB

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