Jenkinsfile 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. def projectProperties = [
  2. [$class: 'BuildDiscarderProperty',
  3. strategy: [$class: 'LogRotator', numToKeepStr: '5']],
  4. pipelineTriggers([cron('@daily')])
  5. ]
  6. properties(projectProperties)
  7. def SUCCESS = hudson.model.Result.SUCCESS.toString()
  8. currentBuild.result = SUCCESS
  9. def ARTIFACTORY_CREDENTIALS = usernamePassword(credentialsId: '02bd1690-b54f-4c9f-819d-a77cb7a9822c', usernameVariable: 'ARTIFACTORY_USERNAME', passwordVariable: 'ARTIFACTORY_PASSWORD')
  10. def JENKINS_USER='-Duser.name="spring-builds+jenkins"'
  11. try {
  12. parallel check: {
  13. stage('Check') {
  14. node {
  15. checkout scm
  16. sh "git clean -dfx"
  17. try {
  18. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  19. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  20. sh "./gradlew $JENKINS_USER clean check -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  21. }
  22. }
  23. } catch(Exception e) {
  24. currentBuild.result = 'FAILED: check'
  25. throw e
  26. }
  27. }
  28. }
  29. },
  30. sonar: {
  31. stage('Sonar') {
  32. node {
  33. checkout scm
  34. sh "git clean -dfx"
  35. withCredentials([string(credentialsId: 'spring-sonar.login', variable: 'SONAR_LOGIN')]) {
  36. try {
  37. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  38. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  39. if ("master" == env.BRANCH_NAME) {
  40. sh "./gradlew $JENKINS_USER sonarqube -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD -PexcludeProjects='**/samples/**' -Dsonar.host.url=$SPRING_SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN --refresh-dependencies --no-daemon --stacktrace"
  41. } else {
  42. sh "./gradlew $JENKINS_USER sonarqube -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD -PexcludeProjects='**/samples/**' -Dsonar.projectKey='spring-security-${env.BRANCH_NAME}' -Dsonar.projectName='spring-security-${env.BRANCH_NAME}' -Dsonar.host.url=$SPRING_SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN --refresh-dependencies --no-daemon --stacktrace"
  43. }
  44. }
  45. }
  46. } catch(Exception e) {
  47. currentBuild.result = 'FAILED: sonar'
  48. throw e
  49. }
  50. }
  51. }
  52. }
  53. },
  54. snapshots: {
  55. stage('Snapshot Tests') {
  56. node {
  57. checkout scm
  58. sh "git clean -dfx"
  59. try {
  60. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  61. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  62. sh "./gradlew $JENKINS_USER clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD -PforceMavenRepositories=snapshot -PspringVersion='5.2.+' -PreactorVersion=Dysprosium-BUILD-SNAPSHOT -PspringDataVersion=Lovelace-BUILD-SNAPSHOT --refresh-dependencies --no-daemon --stacktrace"
  63. }
  64. }
  65. } catch(Exception e) {
  66. currentBuild.result = 'FAILED: snapshots'
  67. throw e
  68. }
  69. }
  70. }
  71. },
  72. jdk11: {
  73. stage('JDK 11') {
  74. node {
  75. checkout scm
  76. sh "git clean -dfx"
  77. try {
  78. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  79. withEnv(["JAVA_HOME=${ tool 'jdk11' }"]) {
  80. sh "./gradlew $JENKINS_USER clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  81. }
  82. }
  83. } catch(Exception e) {
  84. currentBuild.result = 'FAILED: jdk11'
  85. throw e
  86. }
  87. }
  88. }
  89. },
  90. jdk12: {
  91. stage('JDK 12') {
  92. node {
  93. checkout scm
  94. sh "git clean -dfx"
  95. try {
  96. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  97. withEnv(["JAVA_HOME=${ tool 'openjdk12' }"]) {
  98. sh "./gradlew $JENKINS_USER clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  99. }
  100. }
  101. } catch(Exception e) {
  102. currentBuild.result = 'FAILED: jdk12'
  103. throw e
  104. }
  105. }
  106. }
  107. }
  108. if(currentBuild.result == 'SUCCESS') {
  109. parallel artifacts: {
  110. stage('Deploy Artifacts') {
  111. node {
  112. checkout scm
  113. sh "git clean -dfx"
  114. withCredentials([file(credentialsId: 'spring-signing-secring.gpg', variable: 'SIGNING_KEYRING_FILE')]) {
  115. withCredentials([string(credentialsId: 'spring-gpg-passphrase', variable: 'SIGNING_PASSWORD')]) {
  116. withCredentials([usernamePassword(credentialsId: 'oss-s01-token', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USERNAME')]) {
  117. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  118. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  119. sh "./gradlew $JENKINS_USER deployArtifacts finalizeDeployArtifacts -Psigning.secretKeyRingFile=$SIGNING_KEYRING_FILE -Psigning.keyId=$SPRING_SIGNING_KEYID -Psigning.password='$SIGNING_PASSWORD' -PossrhTokenUsername=$OSSRH_USERNAME -PossrhTokenPassword=$OSSRH_PASSWORD -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. },
  128. docs: {
  129. stage('Deploy Docs') {
  130. node {
  131. checkout scm
  132. sh "git clean -dfx"
  133. withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
  134. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  135. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  136. sh "./gradlew $JENKINS_USER deployDocs -PdeployDocsSshKeyPath=$DEPLOY_SSH_KEY -PdeployDocsSshUsername=$SPRING_DOCS_USERNAME -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  137. }
  138. }
  139. }
  140. }
  141. }
  142. },
  143. schema: {
  144. stage('Deploy Schema') {
  145. node {
  146. checkout scm
  147. sh "git clean -dfx"
  148. withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
  149. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  150. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  151. sh "./gradlew $JENKINS_USER deploySchema -PdeployDocsSshKeyPath=$DEPLOY_SSH_KEY -PdeployDocsSshUsername=$SPRING_DOCS_USERNAME --refresh-dependencies --no-daemon --stacktrace"
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. } catch(Exception e) {
  160. currentBuild.result = 'FAILED: deploys'
  161. throw e
  162. } finally {
  163. def buildStatus = currentBuild.result
  164. def buildNotSuccess = !SUCCESS.equals(buildStatus)
  165. def lastBuildNotSuccess = !SUCCESS.equals(currentBuild.previousBuild?.result)
  166. if(buildNotSuccess || lastBuildNotSuccess) {
  167. stage('Notifiy') {
  168. node {
  169. final def RECIPIENTS = [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']]
  170. def subject = "${buildStatus}: Build ${env.JOB_NAME} ${env.BUILD_NUMBER} status is now ${buildStatus}"
  171. def details = """The build status changed to ${buildStatus}. For details see ${env.BUILD_URL}"""
  172. emailext (
  173. subject: subject,
  174. body: details,
  175. recipientProviders: RECIPIENTS,
  176. to: "$SPRING_SECURITY_TEAM_EMAILS"
  177. )
  178. }
  179. }
  180. }
  181. }