Jenkinsfile 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. try {
  11. parallel check: {
  12. stage('Check') {
  13. node {
  14. checkout scm
  15. sh "git clean -dfx"
  16. try {
  17. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  18. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  19. sh "./gradlew clean check -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  20. }
  21. }
  22. } catch(Exception e) {
  23. currentBuild.result = 'FAILED: check'
  24. throw e
  25. } finally {
  26. junit '**/build/test-results/*/*.xml'
  27. }
  28. }
  29. }
  30. },
  31. sonar: {
  32. stage('Sonar') {
  33. node {
  34. checkout scm
  35. sh "git clean -dfx"
  36. withCredentials([string(credentialsId: 'spring-sonar.login', variable: 'SONAR_LOGIN')]) {
  37. try {
  38. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  39. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  40. if ("master" == env.BRANCH_NAME) {
  41. sh "./gradlew 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"
  42. } else {
  43. sh "./gradlew 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"
  44. }
  45. }
  46. }
  47. } catch(Exception e) {
  48. currentBuild.result = 'FAILED: sonar'
  49. throw e
  50. }
  51. }
  52. }
  53. }
  54. },
  55. snapshots: {
  56. stage('Snapshot Tests') {
  57. node {
  58. checkout scm
  59. sh "git clean -dfx"
  60. try {
  61. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  62. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  63. sh "./gradlew 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"
  64. }
  65. }
  66. } catch(Exception e) {
  67. currentBuild.result = 'FAILED: snapshots'
  68. throw e
  69. }
  70. }
  71. }
  72. },
  73. jdk9: {
  74. stage('JDK 9') {
  75. node {
  76. checkout scm
  77. sh "git clean -dfx"
  78. try {
  79. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  80. withEnv(["JAVA_HOME=${ tool 'jdk9' }"]) {
  81. sh "./gradlew clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  82. }
  83. }
  84. } catch(Exception e) {
  85. currentBuild.result = 'FAILED: jdk9'
  86. throw e
  87. }
  88. }
  89. }
  90. },
  91. jdk10: {
  92. stage('JDK 10') {
  93. node {
  94. checkout scm
  95. sh "git clean -dfx"
  96. try {
  97. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  98. withEnv(["JAVA_HOME=${ tool 'jdk10' }"]) {
  99. sh "./gradlew clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  100. }
  101. }
  102. } catch(Exception e) {
  103. currentBuild.result = 'FAILED: jdk10'
  104. throw e
  105. }
  106. }
  107. }
  108. },
  109. jdk11: {
  110. stage('JDK 11') {
  111. node {
  112. checkout scm
  113. sh "git clean -dfx"
  114. try {
  115. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  116. withEnv(["JAVA_HOME=${ tool 'jdk11' }"]) {
  117. sh "./gradlew clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  118. }
  119. }
  120. } catch(Exception e) {
  121. currentBuild.result = 'FAILED: jdk11'
  122. throw e
  123. }
  124. }
  125. }
  126. },
  127. jdk12: {
  128. stage('JDK 12') {
  129. node {
  130. checkout scm
  131. sh "git clean -dfx"
  132. try {
  133. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  134. withEnv(["JAVA_HOME=${ tool 'openjdk12' }"]) {
  135. sh "./gradlew clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  136. }
  137. }
  138. } catch(Exception e) {
  139. currentBuild.result = 'FAILED: jdk12'
  140. throw e
  141. }
  142. }
  143. }
  144. }
  145. if(currentBuild.result == 'SUCCESS') {
  146. parallel artifacts: {
  147. stage('Deploy Artifacts') {
  148. node {
  149. checkout scm
  150. sh "git clean -dfx"
  151. withCredentials([file(credentialsId: 'spring-signing-secring.gpg', variable: 'SIGNING_KEYRING_FILE')]) {
  152. withCredentials([string(credentialsId: 'spring-gpg-passphrase', variable: 'SIGNING_PASSWORD')]) {
  153. withCredentials([usernamePassword(credentialsId: 'oss-token', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USERNAME')]) {
  154. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  155. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  156. sh "./gradlew deployArtifacts finalizeDeployArtifacts -Psigning.secretKeyRingFile=$SIGNING_KEYRING_FILE -Psigning.keyId=$SPRING_SIGNING_KEYID -Psigning.password='$SIGNING_PASSWORD' -PossrhUsername=$OSSRH_USERNAME -PossrhPassword=$OSSRH_PASSWORD -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  157. }
  158. }
  159. }
  160. }
  161. }
  162. }
  163. }
  164. },
  165. docs: {
  166. stage('Deploy Docs') {
  167. node {
  168. checkout scm
  169. sh "git clean -dfx"
  170. withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
  171. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  172. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  173. sh "./gradlew deployDocs -PdeployDocsSshKeyPath=$DEPLOY_SSH_KEY -PdeployDocsSshUsername=$SPRING_DOCS_USERNAME -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  174. }
  175. }
  176. }
  177. }
  178. }
  179. },
  180. schema: {
  181. stage('Deploy Schema') {
  182. node {
  183. checkout scm
  184. sh "git clean -dfx"
  185. withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
  186. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  187. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  188. sh "./gradlew deploySchema -PdeployDocsSshKeyPath=$DEPLOY_SSH_KEY -PdeployDocsSshUsername=$SPRING_DOCS_USERNAME --refresh-dependencies --no-daemon --stacktrace"
  189. }
  190. }
  191. }
  192. }
  193. }
  194. }
  195. }
  196. } catch(Exception e) {
  197. currentBuild.result = 'FAILED: deploys'
  198. throw e
  199. } finally {
  200. def buildStatus = currentBuild.result
  201. def buildNotSuccess = !SUCCESS.equals(buildStatus)
  202. def lastBuildNotSuccess = !SUCCESS.equals(currentBuild.previousBuild?.result)
  203. if(buildNotSuccess || lastBuildNotSuccess) {
  204. stage('Notifiy') {
  205. node {
  206. final def RECIPIENTS = [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']]
  207. def subject = "${buildStatus}: Build ${env.JOB_NAME} ${env.BUILD_NUMBER} status is now ${buildStatus}"
  208. def details = """The build status changed to ${buildStatus}. For details see ${env.BUILD_URL}"""
  209. emailext (
  210. subject: subject,
  211. body: details,
  212. recipientProviders: RECIPIENTS,
  213. to: "$SPRING_SECURITY_TEAM_EMAILS"
  214. )
  215. }
  216. }
  217. }
  218. }