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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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_11_latest'
  31. buildJdk17 = 'jdk_17_latest'
  32. buildMvn = 'maven_3.8.5'
  33. //localRepository = ".repository"
  34. //localRepository = "../.maven_repositories/${env.EXECUTOR_NUMBER}"
  35. mavenOpts = '-Xms1g -Xmx2g -Djava.awt.headless=true'
  36. publishers = [artifactsPublisher(disabled: false),
  37. junitPublisher(disabled: false, ignoreAttachments: false),
  38. pipelineGraphPublisher(disabled: false),mavenLinkerPublisher(disabled: false)]
  39. cmdLine = (env.NONAPACHEORG_RUN != 'y' && env.BRANCH_NAME == 'master') ? "clean deploy" : "clean install"
  40. INTEGRATION_PIPELINE = "/Archiva/Archiva-IntegrationTests"
  41. pipeline {
  42. agent {
  43. label "${LABEL}"
  44. }
  45. // Build should also start, if redback has been built successfully
  46. triggers {
  47. upstream(upstreamProjects: 'Archiva/archiva-projects/archiva-redback-core/master,Archiva/archiva-projects/archiva-components/master,Archiva/archiva-projects/archiva-parent/master', threshold: hudson.model.Result.SUCCESS)
  48. }
  49. options {
  50. disableConcurrentBuilds()
  51. buildDiscarder(logRotator(numToKeepStr: '7', artifactNumToKeepStr: '2'))
  52. }
  53. parameters {
  54. booleanParam(name: 'PRECLEANUP', defaultValue: false, description: 'Clears the local maven repository before build.')
  55. string(name: 'THREADS', defaultValue: '3', description: 'Number of threads for the mvn build (-T option). Must be a integer value>0.')
  56. }
  57. environment {
  58. LOCAL_REPOSITORY = "../.maven_repositories/${env.EXECUTOR_NUMBER}"
  59. }
  60. stages {
  61. stage('PreCleanup') {
  62. when {
  63. expression {
  64. params.PRECLEANUP
  65. }
  66. }
  67. steps {
  68. sh "rm -rf ${env.LOCAL_REPOSITORY}"
  69. }
  70. }
  71. stage('BuildAndDeploy') {
  72. environment {
  73. ARCHIVA_USER_CONFIG_FILE = '/tmp/archiva-master-jdk-8-${env.JOB_NAME}.xml'
  74. }
  75. steps {
  76. timeout(120) {
  77. withMaven(maven: buildMvn, jdk: buildJdk,
  78. mavenLocalRepo: env.LOCAL_REPOSITORY,
  79. publisherStrategy: 'EXPLICIT',
  80. mavenOpts: mavenOpts,
  81. options: publishers )
  82. {
  83. sh "chmod 755 ./src/ci/scripts/prepareWorkspace.sh"
  84. sh "./src/ci/scripts/prepareWorkspace.sh"
  85. // Needs a lot of time to reload the repository files, try without cleanup
  86. // Not sure, but maybe
  87. // sh "rm -rf .repository"
  88. // Run test phase / ignore test failures
  89. // -B: Batch mode
  90. // -U: Force snapshot update
  91. // -e: Produce execution error messages
  92. // -fae: Fail at the end
  93. // -Dmaven.compiler.fork=true: Do compile in a separate forked process
  94. // -Dmaven.test.failure.ignore=true: Do not stop, if some tests fail
  95. // -Pci-build: Profile for CI-Server
  96. sh "mvn ${cmdLine} -B -U -e -fae -Dorg.slf4j.simpleLogger.showThreadName=true -Pci-build -T${params.THREADS}"
  97. }
  98. }
  99. }
  100. post {
  101. always {
  102. sh "rm -f /tmp/archiva-master-jdk-8-${env.JOB_NAME}.xml"
  103. }
  104. failure {
  105. script{
  106. asfStandardBuild.notifyBuild("Failure in BuildAndDeploy stage")
  107. }
  108. }
  109. }
  110. }
  111. stage('Postbuild') {
  112. parallel {
  113. stage('IntegrationTest') {
  114. steps {
  115. build(job: "${INTEGRATION_PIPELINE}/archiva/${env.BRANCH_NAME}", propagate: false, quietPeriod: 5, wait: false)
  116. }
  117. }
  118. stage('JDK17') {
  119. environment {
  120. ARCHIVA_USER_CONFIG_FILE = '/tmp/archiva-master-jdk-17-${env.JOB_NAME}.xml'
  121. }
  122. steps {
  123. ws("${env.JOB_NAME}-JDK11") {
  124. checkout scm
  125. timeout(120) {
  126. withMaven(maven: buildMvn, jdk: buildJdk17,
  127. mavenLocalRepo: ".repository",
  128. publisherStrategy: 'EXPLICIT',
  129. mavenOpts: mavenOpts,
  130. options: publishers
  131. )
  132. {
  133. sh "chmod 755 ./src/ci/scripts/prepareWorkspace.sh"
  134. sh "./src/ci/scripts/prepareWorkspace.sh"
  135. sh "mvn clean install -U -B -e -fae -Dorg.slf4j.simpleLogger.showThreadName=true -Pci-build -T${params.THREADS}"
  136. }
  137. }
  138. }
  139. }
  140. post {
  141. always {
  142. sh "rm -f /tmp/archiva-master-jdk-17-${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