Jenkinsfile 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. pipeline {
  18. agent {
  19. label 'Hadoop'
  20. }
  21. options {
  22. buildDiscarder(logRotator(numToKeepStr: '5'))
  23. timeout (time: 24, unit: 'HOURS')
  24. timestamps()
  25. checkoutToSubdirectory('src')
  26. }
  27. environment {
  28. SOURCEDIR = 'src'
  29. // will also need to change notification section below
  30. PATCHDIR = 'out'
  31. DOCKERFILE = "${SOURCEDIR}/dev-support/docker/Dockerfile"
  32. YETUS='yetus'
  33. // Branch or tag name. Yetus release tags are 'rel/X.Y.Z'
  34. YETUS_VERSION='11eb9b09786e401fbdeaa3be83a19a4066fd7813'
  35. MAVEN_OPTS='-Xms256m -Xmx1536m -Dhttps.protocols=TLSv1.2 -Dhttps.cipherSuites=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256'
  36. }
  37. parameters {
  38. string(name: 'JIRA_ISSUE_KEY',
  39. defaultValue: '',
  40. description: 'The JIRA issue that has a patch needing pre-commit testing. Example: HADOOP-1234')
  41. }
  42. stages {
  43. stage ('install yetus') {
  44. steps {
  45. dir("${WORKSPACE}/${YETUS}") {
  46. checkout([
  47. $class: 'GitSCM',
  48. branches: [[name: "${env.YETUS_VERSION}"]],
  49. userRemoteConfigs: [[ url: 'https://github.com/apache/yetus.git']]]
  50. )
  51. }
  52. }
  53. }
  54. stage ('precommit-run') {
  55. steps {
  56. withCredentials(
  57. [usernamePassword(credentialsId: 'apache-hadoop-at-github.com',
  58. passwordVariable: 'GITHUB_TOKEN',
  59. usernameVariable: 'GITHUB_USER')]) {
  60. sh '''#!/usr/bin/env bash
  61. set -e
  62. TESTPATCHBIN="${WORKSPACE}/${YETUS}/precommit/src/main/shell/test-patch.sh"
  63. # this must be clean for every run
  64. if [[ -d "${WORKSPACE}/${PATCHDIR}" ]]; then
  65. rm -rf "${WORKSPACE}/${PATCHDIR}"
  66. fi
  67. mkdir -p "${WORKSPACE}/${PATCHDIR}"
  68. # if given a JIRA issue, process it. If CHANGE_URL is set
  69. # (e.g., Github Branch Source plugin), process it.
  70. # otherwise exit, because we don't want Hadoop to do a
  71. # full build. We wouldn't normally do this check for smaller
  72. # projects. :)
  73. if [[ -n "${JIRA_ISSUE_KEY}" ]]; then
  74. YETUS_ARGS+=("${JIRA_ISSUE_KEY}")
  75. elif [[ -z "${CHANGE_URL}" ]]; then
  76. echo "Full build skipped" > "${WORKSPACE}/${PATCHDIR}/report.html"
  77. exit 0
  78. fi
  79. YETUS_ARGS+=("--patch-dir=${WORKSPACE}/${PATCHDIR}")
  80. # where the source is located
  81. YETUS_ARGS+=("--basedir=${WORKSPACE}/${SOURCEDIR}")
  82. # our project defaults come from a personality file
  83. YETUS_ARGS+=("--project=hadoop")
  84. YETUS_ARGS+=("--personality=${WORKSPACE}/${SOURCEDIR}/dev-support/bin/hadoop.sh")
  85. # lots of different output formats
  86. YETUS_ARGS+=("--brief-report-file=${WORKSPACE}/${PATCHDIR}/brief.txt")
  87. YETUS_ARGS+=("--console-report-file=${WORKSPACE}/${PATCHDIR}/console.txt")
  88. YETUS_ARGS+=("--html-report-file=${WORKSPACE}/${PATCHDIR}/report.html")
  89. # enable writing back to Github
  90. YETUS_ARGS+=(--github-token="${GITHUB_TOKEN}")
  91. # auto-kill any surefire stragglers during unit test runs
  92. YETUS_ARGS+=("--reapermode=kill")
  93. # set relatively high limits for ASF machines
  94. # changing these to higher values may cause problems
  95. # with other jobs on systemd-enabled machines
  96. YETUS_ARGS+=("--proclimit=5500")
  97. YETUS_ARGS+=("--dockermemlimit=22g")
  98. # -1 spotbugs issues that show up prior to the patch being applied
  99. YETUS_ARGS+=("--spotbugs-strict-precheck")
  100. # rsync these files back into the archive dir
  101. YETUS_ARGS+=("--archive-list=checkstyle-errors.xml,spotbugsXml.xml")
  102. # URL for user-side presentation in reports and such to our artifacts
  103. # (needs to match the archive bits below)
  104. YETUS_ARGS+=("--build-url-artifacts=artifact/out")
  105. # plugins to enable
  106. YETUS_ARGS+=("--plugins=all,-jira")
  107. # don't let these tests cause -1s because we aren't really paying that
  108. # much attention to them
  109. YETUS_ARGS+=("--tests-filter=checkstyle")
  110. # run in docker mode and specifically point to our
  111. # Dockerfile since we don't want to use the auto-pulled version.
  112. YETUS_ARGS+=("--docker")
  113. YETUS_ARGS+=("--dockerfile=${DOCKERFILE}")
  114. YETUS_ARGS+=("--mvn-custom-repos")
  115. # effectively treat dev-suport as a custom maven module
  116. YETUS_ARGS+=("--skip-dirs=dev-support")
  117. # help keep the ASF boxes clean
  118. YETUS_ARGS+=("--sentinel")
  119. # Use both Java 7 and 8
  120. YETUS_ARGS+=("--java-home=/usr/lib/jvm/java-8-openjdk-amd64")
  121. YETUS_ARGS+=("--multijdkdirs=/usr/lib/jvm/zulu-7-amd64")
  122. YETUS_ARGS+=("--multijdktests=compile")
  123. # write Yetus report as GitHub comment (YETUS-1102)
  124. YETUS_ARGS+=("--github-write-comment")
  125. YETUS_ARGS+=("--github-use-emoji-vote")
  126. "${TESTPATCHBIN}" "${YETUS_ARGS[@]}"
  127. '''
  128. }
  129. }
  130. }
  131. }
  132. post {
  133. always {
  134. script {
  135. // Publish status if it was missed (YETUS-1059)
  136. withCredentials(
  137. [usernamePassword(credentialsId: '683f5dcf-5552-4b28-9fb1-6a6b77cf53dd',
  138. passwordVariable: 'GITHUB_TOKEN',
  139. usernameVariable: 'GITHUB_USER')]) {
  140. sh '''#!/usr/bin/env bash
  141. YETUS_ARGS+=("--github-token=${GITHUB_TOKEN}")
  142. YETUS_ARGS+=("--patch-dir=${WORKSPACE}/${PATCHDIR}")
  143. TESTPATCHBIN="${WORKSPACE}/${YETUS}/precommit/src/main/shell/github-status-recovery.sh"
  144. /usr/bin/env bash "${TESTPATCHBIN}" "${YETUS_ARGS[@]}" ${EXTRA_ARGS} || true
  145. '''
  146. }
  147. // Yetus output
  148. archiveArtifacts "${env.PATCHDIR}/**"
  149. // Publish the HTML report so that it can be looked at
  150. // Has to be relative to WORKSPACE.
  151. publishHTML (target: [
  152. allowMissing: true,
  153. keepAll: true,
  154. alwaysLinkToLastBuild: true,
  155. // Has to be relative to WORKSPACE
  156. reportDir: "${env.PATCHDIR}",
  157. reportFiles: 'report.html',
  158. reportName: 'Yetus Report'
  159. ])
  160. // Publish JUnit results
  161. try {
  162. junit "${env.SOURCEDIR}/**/target/surefire-reports/*.xml"
  163. } catch(e) {
  164. echo 'junit processing: ' + e.toString()
  165. }
  166. }
  167. }
  168. // Jenkins pipeline jobs fill slaves on PRs without this :(
  169. cleanup() {
  170. script {
  171. sh '''
  172. # See YETUS-764
  173. if [ -f "${WORKSPACE}/${PATCHDIR}/pidfile.txt" ]; then
  174. echo "test-patch process appears to still be running: killing"
  175. kill `cat "${WORKSPACE}/${PATCHDIR}/pidfile.txt"` || true
  176. sleep 10
  177. fi
  178. if [ -f "${WORKSPACE}/${PATCHDIR}/cidfile.txt" ]; then
  179. echo "test-patch container appears to still be running: killing"
  180. docker kill `cat "${WORKSPACE}/${PATCHDIR}/cidfile.txt"` || true
  181. fi
  182. # See HADOOP-13951
  183. chmod -R u+rxw "${WORKSPACE}"
  184. '''
  185. deleteDir()
  186. }
  187. }
  188. }
  189. }