Jenkinsfile 12 KB

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