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 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. buildJdk11 = 'JDK 11 (latest)'
  34. buildMvn = 'Maven 3.5.4'
  35. //localRepository = ".repository"
  36. //localRepository = "../.maven_repositories/${env.EXECUTOR_NUMBER}"
  37. mavenOpts = '-Xms1g -Xmx2g -Djava.awt.headless=true'
  38. publishers = [artifactsPublisher(disabled: false),
  39. junitPublisher(disabled: false, ignoreAttachments: false),
  40. pipelineGraphPublisher(disabled: false),mavenLinkerPublisher(disabled: false)]
  41. INTEGRATION_PIPELINE = "Archiva-IntegrationTests-Gitbox"
  42. pipeline {
  43. agent {
  44. label "${LABEL}"
  45. }
  46. options {
  47. disableConcurrentBuilds()
  48. buildDiscarder(logRotator(numToKeepStr: '7', artifactNumToKeepStr: '5'))
  49. }
  50. parameters {
  51. booleanParam(name: 'PRECLEANUP', defaultValue: false, description: 'Clears the local maven repository before build.')
  52. string(name: 'THREADS', defaultValue: '3', description: 'Number of threads for the mvn build (-T option). Must be a integer value>0.')
  53. }
  54. environment {
  55. LOCAL_REPOSITORY = "../.maven_repositories/${env.EXECUTOR_NUMBER}"
  56. }
  57. stages {
  58. stage('PreCleanup') {
  59. when {
  60. expression {
  61. params.PRECLEANUP
  62. }
  63. }
  64. steps {
  65. sh "rm -rf ${env.LOCAL_REPOSITORY}"
  66. }
  67. }
  68. stage('BuildAndDeploy') {
  69. environment {
  70. ARCHIVA_USER_CONFIG_FILE = '/tmp/archiva-master-jdk-8-${env.JOB_NAME}.xml'
  71. }
  72. steps {
  73. timeout(120) {
  74. withMaven(maven: buildMvn, jdk: buildJdk,
  75. mavenLocalRepo: env.LOCAL_REPOSITORY,
  76. publisherStrategy: 'EXPLICIT',
  77. mavenOpts: mavenOpts,
  78. options: publishers )
  79. {
  80. sh "chmod 755 ./src/ci/scripts/prepareWorkspace.sh"
  81. sh "./src/ci/scripts/prepareWorkspace.sh"
  82. // Needs a lot of time to reload the repository files, try without cleanup
  83. // Not sure, but maybe
  84. // sh "rm -rf .repository"
  85. // Run test phase / ignore test failures
  86. // -B: Batch mode
  87. // -U: Force snapshot update
  88. // -e: Produce execution error messages
  89. // -fae: Fail at the end
  90. // -Dmaven.compiler.fork=true: Do compile in a separate forked process
  91. // -Dmaven.test.failure.ignore=true: Do not stop, if some tests fail
  92. // -Pci-build: Profile for CI-Server
  93. sh "mvn clean deploy -B -U -e -fae -Dmaven.compiler.fork=true -Pci-build -T${THREADS}"
  94. }
  95. }
  96. }
  97. post {
  98. always {
  99. sh "rm -f /tmp/archiva-master-jdk-8-${env.JOB_NAME}.xml"
  100. }
  101. failure {
  102. script{
  103. asfStandardBuild.notifyBuild("Failure in BuildAndDeploy stage")
  104. }
  105. }
  106. }
  107. }
  108. stage('Postbuild') {
  109. parallel {
  110. stage('IntegrationTest') {
  111. steps {
  112. build(job: "${INTEGRATION_PIPELINE}/archiva/${env.BRANCH_NAME}", propagate: false, quietPeriod: 5, wait: false)
  113. }
  114. }
  115. stage('JDK11') {
  116. environment {
  117. ARCHIVA_USER_CONFIG_FILE = '/tmp/archiva-master-jdk-11-${env.JOB_NAME}.xml'
  118. }
  119. steps {
  120. ws("${env.JOB_NAME}-JDK11") {
  121. checkout scm
  122. timeout(120) {
  123. withMaven(maven: buildMvn, jdk: buildJdk11,
  124. mavenLocalRepo: ".repository",
  125. publisherStrategy: 'EXPLICIT',
  126. mavenOpts: mavenOpts,
  127. options: publishers
  128. )
  129. {
  130. sh "mvn clean install -U -B -e -fae -Dmaven.compiler.fork=true -Pci-build -T${THREADS}"
  131. }
  132. }
  133. }
  134. }
  135. post {
  136. always {
  137. sh "rm -f /tmp/archiva-master-jdk-11-${env.JOB_NAME}.xml"
  138. }
  139. success {
  140. cleanWs()
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }
  147. post {
  148. unstable {
  149. script {
  150. asfStandardBuild.notifyBuild("Unstable Build")
  151. }
  152. }
  153. success {
  154. script {
  155. def previousResult = currentBuild.previousBuild?.result
  156. if (previousResult && !currentBuild.resultIsWorseOrEqualTo(previousResult)) {
  157. asfStandardBuild.notifyBuild("Fixed")
  158. }
  159. }
  160. }
  161. }
  162. }
  163. // vim: et:ts=4:sw=4:ft=groovy