Jenkinsfile 8.8 KB

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