You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Jenkinsfile 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * Main build file for Jenkins Multibranch pipeline.
  21. *
  22. * The pipeline builds, runs the test and deploys to the archiva snapshot repository.
  23. *
  24. * Uses one stage for build and deploy to avoid running it multiple times.
  25. * The settings for deployment with the credentials must be provided by a MavenSettingsProvider.
  26. *
  27. * Only the war and zip artifacts are archived in the jenkins build archive.
  28. */
  29. LABEL = 'ubuntu'
  30. buildJdk = 'JDK 1.8 (latest)'
  31. buildJdk9 = 'JDK 1.9 (latest)'
  32. buildJdk10 = 'JDK 10 (latest)'
  33. buildMvn = 'Maven 3.5.2'
  34. deploySettings = 'archiva-uid-jenkins'
  35. localRepository = "../.archiva-master-repository"
  36. mavenOpts = '-Xms1g -Xmx2g -Djava.awt.headless=true'
  37. INTEGRATION_PIPELINE = "Archiva-IntegrationTests-Gitbox"
  38. pipeline {
  39. agent {
  40. label "${LABEL}"
  41. }
  42. options {
  43. disableConcurrentBuilds()
  44. }
  45. parameters {
  46. booleanParam(name: 'PRECLEANUP', defaultValue: false, description: 'Clears the local maven repository before build.')
  47. }
  48. stages {
  49. stage('PreCleanup') {
  50. when {
  51. expression {
  52. params.PRECLEANUP
  53. }
  54. }
  55. steps {
  56. sh "rm -rf ${localRepository}"
  57. }
  58. }
  59. stage('BuildAndDeploy') {
  60. environment {
  61. ARCHIVA_USER_CONFIG_FILE = '/tmp/archiva-master-jdk-8-${env.JOB_NAME}.xml'
  62. }
  63. steps {
  64. timeout(120) {
  65. withMaven(maven: buildMvn, jdk: buildJdk,
  66. mavenSettingsConfig: deploySettings,
  67. mavenLocalRepo: localRepository,
  68. publisherStrategy: 'EXPLICIT',
  69. mavenOpts: mavenOpts,
  70. options: [artifactsPublisher(disabled: false),
  71. junitPublisher(disabled: false, ignoreAttachments: false),
  72. pipelineGraphPublisher(disabled: false)]
  73. )
  74. {
  75. sh "chmod 755 ./src/ci/scripts/prepareWorkspace.sh"
  76. sh "./src/ci/scripts/prepareWorkspace.sh"
  77. // Needs a lot of time to reload the repository files, try without cleanup
  78. // Not sure, but maybe
  79. // sh "rm -rf .repository"
  80. // Run test phase / ignore test failures
  81. // -B: Batch mode
  82. // -U: Force snapshot update
  83. // -e: Produce execution error messages
  84. // -fae: Fail at the end
  85. // -Dmaven.compiler.fork=true: Do compile in a separate forked process
  86. // -Dmaven.test.failure.ignore=true: Do not stop, if some tests fail
  87. // -Pci-build: Profile for CI-Server
  88. sh "mvn clean deploy -B -U -e -fae -Dmaven.compiler.fork=true -Pci-build"
  89. }
  90. }
  91. }
  92. post {
  93. always {
  94. sh "rm -f /tmp/archiva-master-jdk-8-${env.JOB_NAME}.xml"
  95. }
  96. failure {
  97. notifyBuild("Failure in BuildAndDeploy stage")
  98. }
  99. }
  100. }
  101. stage('Postbuild') {
  102. parallel {
  103. stage('IntegrationTest') {
  104. steps {
  105. build(job: "${INTEGRATION_PIPELINE}/archiva/${env.BRANCH_NAME}", propagate: false, quietPeriod: 5, wait: false)
  106. }
  107. }
  108. stage('JDK9') {
  109. environment {
  110. ARCHIVA_USER_CONFIG_FILE = '/tmp/archiva-master-jdk-9-${env.JOB_NAME}.xml'
  111. }
  112. steps {
  113. ws("${env.JOB_NAME}-JDK9") {
  114. checkout scm
  115. timeout(120) {
  116. withMaven(maven: buildMvn, jdk: buildJdk9,
  117. publisherStrategy: 'EXPLICIT',
  118. mavenOpts: mavenOpts,
  119. mavenSettingsConfig: deploySettings,
  120. mavenLocalRepo: ".repository",
  121. options: [junitPublisher(disabled: false, ignoreAttachments: false)]
  122. )
  123. {
  124. sh "mvn clean install -U -B -e -fae -Dmaven.compiler.fork=true -Pci-build"
  125. }
  126. }
  127. }
  128. }
  129. post {
  130. always {
  131. sh "rm -f /tmp/archiva-master-jdk-9-${env.JOB_NAME}.xml"
  132. }
  133. success {
  134. cleanWs deleteDirs: true, notFailBuild: true, patterns: [[pattern: '.repository', type: 'EXCLUDE']]
  135. }
  136. }
  137. }
  138. stage('JDK10') {
  139. environment {
  140. ARCHIVA_USER_CONFIG_FILE = '/tmp/archiva-master-jdk-10-${env.JOB_NAME}.xml'
  141. }
  142. steps {
  143. ws("${env.JOB_NAME}-JDK10") {
  144. checkout scm
  145. timeout(120) {
  146. withMaven(maven: buildMvn, jdk: buildJdk10,
  147. mavenSettingsConfig: deploySettings,
  148. mavenLocalRepo: ".repository",
  149. publisherStrategy: 'EXPLICIT',
  150. mavenOpts: mavenOpts,
  151. options: [junitPublisher(disabled: false, ignoreAttachments: false)]
  152. )
  153. {
  154. sh "mvn clean install -U -B -e -fae -Dmaven.compiler.fork=true -Pci-build"
  155. }
  156. }
  157. }
  158. }
  159. post {
  160. always {
  161. sh "rm -f /tmp/archiva-master-jdk-10-${env.JOB_NAME}.xml"
  162. }
  163. success {
  164. cleanWs deleteDirs: true, notFailBuild: true, patterns: [[pattern: '.repository', type: 'EXCLUDE']]
  165. }
  166. }
  167. }
  168. }
  169. }
  170. }
  171. post {
  172. unstable {
  173. notifyBuild("Unstable Build")
  174. }
  175. success {
  176. script {
  177. def previousResult = currentBuild.previousBuild?.result
  178. if (previousResult && !currentBuild.resultIsWorseOrEqualTo(previousResult)) {
  179. notifyBuild("Fixed")
  180. }
  181. }
  182. }
  183. }
  184. }
  185. // Send a notification about the build status
  186. def notifyBuild(String buildStatus) {
  187. // default the value
  188. buildStatus = buildStatus ?: "UNKNOWN"
  189. def email = "notifications@archiva.apache.org"
  190. def summary = "${env.JOB_NAME}#${env.BUILD_NUMBER} - ${buildStatus} - ${currentBuild?.currentResult}"
  191. def detail = """<h4>Job: <a href='${env.JOB_URL}'>${env.JOB_NAME}</a> [#${env.BUILD_NUMBER}]</h4>
  192. <p><b>${buildStatus}</b></p>
  193. <table>
  194. <tr><td>Build</td><td><a href='${env.BUILD_URL}'>${env.BUILD_URL}</a></td><tr>
  195. <tr><td>Console</td><td><a href='${env.BUILD_URL}console'>${env.BUILD_URL}console</a></td><tr>
  196. <tr><td>Test Report</td><td><a href='${env.BUILD_URL}testReport/'>${env.BUILD_URL}testReport/</a></td><tr>
  197. </table>
  198. """
  199. emailext(
  200. to: email,
  201. subject: summary,
  202. body: detail,
  203. mimeType: 'text/html'
  204. )
  205. }
  206. // vim: et:ts=4:sw=4:ft=groovy