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