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.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. INTEGRATION_PIPELINE = "Archiva-IntegrationTests-Gitbox"
  36. pipeline {
  37. agent {
  38. label "${LABEL}"
  39. }
  40. stages {
  41. stage('BuildAndDeploy') {
  42. steps {
  43. timeout(120) {
  44. withMaven(maven: buildMvn, jdk: buildJdk,
  45. mavenSettingsConfig: deploySettings,
  46. mavenLocalRepo: ".repository",
  47. options: [concordionPublisher(disabled: true), dependenciesFingerprintPublisher(disabled: true),
  48. findbugsPublisher(disabled: true), artifactsPublisher(disabled: true),
  49. invokerPublisher(disabled: true), jgivenPublisher(disabled: true),
  50. junitPublisher(disabled: true, ignoreAttachments: false),
  51. openTasksPublisher(disabled: true), pipelineGraphPublisher(disabled: true)]
  52. )
  53. {
  54. sh "chmod 755 ./src/ci/scripts/prepareWorkspace.sh"
  55. sh "./src/ci/scripts/prepareWorkspace.sh"
  56. // Needs a lot of time to reload the repository files, try without cleanup
  57. // Not sure, but maybe
  58. // sh "rm -rf .repository"
  59. // Run test phase / ignore test failures
  60. // -B: Batch mode
  61. // -U: Force snapshot update
  62. // -e: Produce execution error messages
  63. // -fae: Fail at the end
  64. // -Dmaven.compiler.fork=true: Do compile in a separate forked process
  65. // -Dmaven.test.failure.ignore=true: Do not stop, if some tests fail
  66. // -Pci-build: Profile for CI-Server
  67. sh "mvn clean deploy -B -U -e -fae -T2 -Dmaven.compiler.fork=true -Pci-build"
  68. }
  69. }
  70. }
  71. post {
  72. always {
  73. junit testResults: '**/target/surefire-reports/TEST-*.xml'
  74. }
  75. success {
  76. archiveArtifacts '**/target/*.war,**/target/*-bin.zip'
  77. }
  78. failure {
  79. notifyBuild("Failure in BuildAndDeploy stage")
  80. }
  81. }
  82. }
  83. stage('IntegrationTest') {
  84. steps {
  85. build(job: "${INTEGRATION_PIPELINE}/archiva/${env.BRANCH_NAME}", propagate: false, quietPeriod: 10)
  86. }
  87. }
  88. stage('JDKs') {
  89. parallel {
  90. stage('JDK9') {
  91. steps {
  92. ws("${env.JOB_NAME}-JDK9") {
  93. checkout scm
  94. timeout(120) {
  95. withMaven(maven: buildMvn, jdk: buildJdk9,
  96. mavenSettingsConfig: deploySettings,
  97. mavenLocalRepo: ".repository",
  98. options: [concordionPublisher(disabled: true), dependenciesFingerprintPublisher(disabled: true),
  99. findbugsPublisher(disabled: true), artifactsPublisher(disabled: true),
  100. invokerPublisher(disabled: true), jgivenPublisher(disabled: true),
  101. junitPublisher(disabled: true, ignoreAttachments: false),
  102. openTasksPublisher(disabled: true), pipelineGraphPublisher(disabled: true)]
  103. )
  104. {
  105. sh "mvn clean install -B -U -e -fae -T2 -Dmaven.compiler.fork=true -Pci-build"
  106. }
  107. }
  108. }
  109. }
  110. }
  111. stage('JDK10') {
  112. steps {
  113. ws("${env.JOB_NAME}-JDK10") {
  114. checkout scm
  115. timeout(120) {
  116. withMaven(maven: buildMvn, jdk: buildJdk10,
  117. mavenSettingsConfig: deploySettings,
  118. mavenLocalRepo: ".repository",
  119. options: [concordionPublisher(disabled: true), dependenciesFingerprintPublisher(disabled: true),
  120. findbugsPublisher(disabled: true), artifactsPublisher(disabled: true),
  121. invokerPublisher(disabled: true), jgivenPublisher(disabled: true),
  122. junitPublisher(disabled: true, ignoreAttachments: false),
  123. openTasksPublisher(disabled: true), pipelineGraphPublisher(disabled: true)]
  124. )
  125. {
  126. sh "mvn clean install -B -U -e -fae -T2 -Dmaven.compiler.fork=true -Pci-build"
  127. }
  128. }
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. post {
  136. unstable {
  137. notifyBuild("Unstable Build")
  138. }
  139. success {
  140. script {
  141. def previousResult = currentBuild.previousBuild?.result
  142. if (previousResult && !currentBuild.resultIsWorseOrEqualTo(previousResult)) {
  143. notifyBuild("Fixed")
  144. }
  145. }
  146. }
  147. always {
  148. cleanWs()
  149. }
  150. }
  151. }
  152. // Send a notification about the build status
  153. def notifyBuild(String buildStatus) {
  154. // default the value
  155. buildStatus = buildStatus ?: "UNKNOWN"
  156. def email = "notifications@archiva.apache.org"
  157. def summary = "${env.JOB_NAME}#${env.BUILD_NUMBER} - ${buildStatus} - ${currentBuild?.currentResult}"
  158. def detail = """<h4>Job: <a href='${env.JOB_URL}'>${env.JOB_NAME}</a> [#${env.BUILD_NUMBER}]</h4>
  159. <p><b>${buildStatus}</b></p>
  160. <table>
  161. <tr><td>Build</td><td><a href='${env.BUILD_URL}'>${env.BUILD_URL}</a></td><tr>
  162. <tr><td>Console</td><td><a href='${env.BUILD_URL}console'>${env.BUILD_URL}console</a></td><tr>
  163. <tr><td>Test Report</td><td><a href='${env.BUILD_URL}testReport/'>${env.BUILD_URL}testReport/</a></td><tr>
  164. </table>
  165. """
  166. emailext(
  167. to: email,
  168. subject: summary,
  169. body: detail,
  170. mimeType: 'text/html'
  171. )
  172. }
  173. // vim: et:ts=4:sw=4:ft=groovy