Jenkinsfile 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. node("ubuntu") {
  19. docker.image('elek/ozone-build').pull()
  20. docker.image('elek/ozone-build').inside("--privileged") {
  21. stage('Checkout') {
  22. checkout scm
  23. //use this for external Jenkinsfile builds
  24. //checkout poll: false, scm: [$class: 'GitSCM', branches: [[name: env.branch]], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'github-token', url: "https://github.com/${organization}/${repository}.git"]]]
  25. }
  26. stage('Clean') {
  27. status = sh returnStatus: true, script: 'mvn clean -P hdds -am -pl :hadoop-ozone-dist '
  28. }
  29. stageRunner('Author', "author", {})
  30. stageRunner('Licence', "rat", {
  31. archiveArtifacts 'target/rat-aggregated.txt'
  32. }, 'artifact/target/rat-aggregated.txt/*view*/')
  33. stageRunner('Build', "build", {})
  34. stageRunner('Findbugs', "findbugs", {
  35. archiveArtifacts 'target/findbugs-all.txt'
  36. }, 'artifact/target/findbugs-all.txt/*view*/')
  37. stageRunner('Checkstyle', "checkstyle", {
  38. checkstyle canComputeNew: false, canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: '**/checkstyle-errors.xml', unHealthy: ''
  39. }, 'checkstyleResult')
  40. stageRunner('Acceptance', "acceptance", {
  41. archiveArtifacts 'hadoop-ozone/dist/target/ozone-0.4.0-SNAPSHOT/smoketest/result/**'
  42. })
  43. stageRunner('Unit test', "unit", {
  44. junit '**/target/surefire-reports/*.xml'
  45. }, 'testReport/')
  46. }
  47. }
  48. def stageRunner(name, type, processResult, url = '') {
  49. try {
  50. stage(name) {
  51. prStatusStart(type)
  52. status = sh returnStatus: true, script: 'hadoop-ozone/dev-support/checks/' + type + '.sh'
  53. processResult()
  54. prStatusResult(status, type, url)
  55. }
  56. return true
  57. } catch (RuntimeException ex) {
  58. currentBuild.result = "FAILED"
  59. return false
  60. }
  61. }
  62. def githubStatus(name, status, description, url='') {
  63. commitId = sh(returnStdout: true, script: 'git rev-parse HEAD')
  64. context = 'ci/ozone/' + name
  65. if (url) {
  66. githubNotify account: 'apache', context: context, credentialsId: 'github-pr-ozone', description: description, repo: 'hadoop', sha: commitId, status: status, targetUrl: url
  67. } else {
  68. githubNotify account: 'apache', context: context, credentialsId: 'github-pr-ozone', description: description, repo: 'hadoop', sha: commitId, status: status
  69. }
  70. }
  71. def prStatusStart(name) {
  72. githubStatus(name,
  73. "PENDING",
  74. name + " is started")
  75. }
  76. def prStatusResult(responseCode, name, url = '') {
  77. status = "ERROR"
  78. desc = "failed"
  79. if (responseCode == 0) {
  80. status = "SUCCESS"
  81. desc = "passed"
  82. }
  83. message = name + " check is " + desc
  84. if (url) {
  85. githubStatus(name,
  86. status,
  87. message,
  88. env.BUILD_URL + url)
  89. } else {
  90. githubStatus(name,
  91. status,
  92. message)
  93. }
  94. if (responseCode != 0) {
  95. throw new RuntimeException(message)
  96. }
  97. }