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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. buildMvn = 'maven_3.5.4'
  32. deploySettings = 'archiva-uid-jenkins'
  33. INTEGRATION_PIPELINE = "Archiva-IntegrationTests-Gitbox"
  34. pipeline {
  35. agent {
  36. label "${LABEL}"
  37. }
  38. options {
  39. buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '2'))
  40. }
  41. stages {
  42. stage('BuildAndDeploy') {
  43. steps {
  44. timeout(120) {
  45. withEnv(["JAVA_HOME=${ tool "$buildJdk" }",
  46. "PATH+MAVEN=${ tool "$buildJdk" }/bin:${tool "$buildMvn"}/bin",
  47. "MAVEN_OPTS=-Xms2g -Xmx4g -Djava.awt.headless=true"]) {
  48. configFileProvider(
  49. [configFile(fileId: 'archiva-uid-jenkins', variable: 'GLOBAL_MVN_SETTINGS')]) {
  50. // Needs a lot of time to reload the repository files, try without cleanup
  51. // Not sure, but maybe
  52. // sh "rm -rf .repository"
  53. sh "chmod 755 ./src/ci/scripts/prepareWorkspace.sh"
  54. sh "./src/ci/scripts/prepareWorkspace.sh -d .repository"
  55. // Run test phase / ignore test failures
  56. // -B: Batch mode
  57. // -U: Force snapshot update
  58. // -e: Produce execution error messages
  59. // -fae: Fail at the end
  60. // -Dmaven.compiler.fork=false: Do not compile in a separate forked process
  61. // -Dmaven.test.failure.ignore=true: Do not stop, if some tests fail
  62. // -Pci-build: Profile for CI-Server
  63. script {
  64. if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'archiva-2.x') {
  65. sh "mvn clean deploy -B -U -e -fae -T2 -Pci-build -DretryFailedDeploymentCount=5 -s $GLOBAL_MVN_SETTINGS -Dmaven.repo.local=.repository"
  66. } else {
  67. sh "mvn clean install -B -U -e -fae -T2 -Pci-build -s $GLOBAL_MVN_SETTINGS -Dmaven.repo.local=.repository"
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. post {
  75. always {
  76. junit testResults: '**/target/surefire-reports/TEST-*.xml'
  77. }
  78. success {
  79. archiveArtifacts '**/target/*.war,**/target/*-bin.zip'
  80. script {
  81. def previousResult = currentBuild.previousBuild?.result
  82. if (previousResult && !currentBuild.resultIsWorseOrEqualTo(previousResult)) {
  83. notifyBuild("Fixed")
  84. }
  85. }
  86. }
  87. failure {
  88. notifyBuild("Failed in BuildAndDeploy stage")
  89. }
  90. }
  91. }
  92. }
  93. post {
  94. unstable {
  95. notifyBuild("Unstable Build")
  96. }
  97. always {
  98. cleanWs deleteDirs: true, notFailBuild: true, patterns: [[pattern: '.repository', type: 'EXCLUDE']]
  99. }
  100. }
  101. }
  102. // Send a notification about the build status
  103. def notifyBuild(String buildStatus) {
  104. // default the value
  105. buildStatus = buildStatus ?: "UNKNOWN"
  106. def email = "notifications@archiva.apache.org"
  107. def summary = "${env.JOB_NAME}#${env.BUILD_NUMBER} - ${buildStatus} - ${currentBuild?.currentResult}"
  108. def detail = """<h4>Job: <a href='${env.JOB_URL}'>${env.JOB_NAME}</a> [#${env.BUILD_NUMBER}]</h4>
  109. <p><b>${buildStatus}</b></p>
  110. <table>
  111. <tr><td>Build</td><td><a href='${env.BUILD_URL}'>${env.BUILD_URL}</a></td><tr>
  112. <tr><td>Console</td><td><a href='${env.BUILD_URL}console'>${env.BUILD_URL}console</a></td><tr>
  113. <tr><td>Test Report</td><td><a href='${env.BUILD_URL}testReport/'>${env.BUILD_URL}testReport/</a></td><tr>
  114. </table>
  115. """
  116. emailext(
  117. to: email,
  118. subject: summary,
  119. body: detail,
  120. mimeType: 'text/html'
  121. )
  122. }
  123. // vim: et:ts=4:sw=4:ft=groovy