Jenkinsfile 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. withEnv(["JAVA_HOME=${ tool 'jdk9' }"]) {
  80. sh "./gradlew clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  81. }
  82. } catch(Exception e) {
  83. currentBuild.result = 'FAILED: jdk9'
  84. throw e
  85. }
  86. }
  87. }
  88. },
  89. jdk10: {
  90. stage('JDK 10') {
  91. node {
  92. checkout scm
  93. sh "git clean -dfx"
  94. try {
  95. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  96. withEnv(["JAVA_HOME=${ tool 'jdk10' }"]) {
  97. sh "./gradlew clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  98. }
  99. }
  100. } catch(Exception e) {
  101. currentBuild.result = 'FAILED: jdk10'
  102. throw e
  103. }
  104. }
  105. }
  106. },
  107. jdk11: {
  108. stage('JDK 11') {
  109. node {
  110. checkout scm
  111. sh "git clean -dfx"
  112. try {
  113. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  114. withEnv(["JAVA_HOME=${ tool 'jdk11' }"]) {
  115. sh "./gradlew clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  116. }
  117. }
  118. } catch(Exception e) {
  119. currentBuild.result = 'FAILED: jdk11'
  120. throw e
  121. }
  122. }
  123. }
  124. },
  125. jdk12: {
  126. stage('JDK 12') {
  127. node {
  128. checkout scm
  129. sh "git clean -dfx"
  130. try {
  131. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  132. withEnv(["JAVA_HOME=${ tool 'openjdk12' }"]) {
  133. sh "./gradlew clean test -PartifactoryUsername=$ARTIFACTORY_USERNAME -PartifactoryPassword=$ARTIFACTORY_PASSWORD --refresh-dependencies --no-daemon --stacktrace"
  134. }
  135. }
  136. } catch(Exception e) {
  137. currentBuild.result = 'FAILED: jdk12'
  138. throw e
  139. }
  140. }
  141. }
  142. }
  143. if(currentBuild.result == 'SUCCESS') {
  144. parallel artifacts: {
  145. stage('Deploy Artifacts') {
  146. node {
  147. checkout scm
  148. sh "git clean -dfx"
  149. withCredentials([file(credentialsId: 'spring-signing-secring.gpg', variable: 'SIGNING_KEYRING_FILE')]) {
  150. withCredentials([string(credentialsId: 'spring-gpg-passphrase', variable: 'SIGNING_PASSWORD')]) {
  151. withCredentials([usernamePassword(credentialsId: 'oss-token', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USERNAME')]) {
  152. withCredentials([ARTIFACTORY_CREDENTIALS]) {
  153. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  154. 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"
  155. }
  156. }
  157. }
  158. }
  159. }
  160. }
  161. }
  162. },
  163. docs: {
  164. stage('Deploy Docs') {
  165. node {
  166. checkout scm
  167. sh "git clean -dfx"
  168. withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
  169. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  170. sh "./gradlew deployDocs -PdeployDocsSshKeyPath=$DEPLOY_SSH_KEY -PdeployDocsSshUsername=$SPRING_DOCS_USERNAME --refresh-dependencies --no-daemon --stacktrace"
  171. }
  172. }
  173. }
  174. }
  175. },
  176. schema: {
  177. stage('Deploy Schema') {
  178. node {
  179. checkout scm
  180. sh "git clean -dfx"
  181. withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
  182. withEnv(["JAVA_HOME=${ tool 'jdk8' }"]) {
  183. sh "./gradlew deploySchema -PdeployDocsSshKeyPath=$DEPLOY_SSH_KEY -PdeployDocsSshUsername=$SPRING_DOCS_USERNAME --refresh-dependencies --no-daemon --stacktrace"
  184. }
  185. }
  186. }
  187. }
  188. }
  189. }
  190. } catch(Exception e) {
  191. currentBuild.result = 'FAILED: deploys'
  192. throw e
  193. } finally {
  194. def buildStatus = currentBuild.result
  195. def buildNotSuccess = !SUCCESS.equals(buildStatus)
  196. def lastBuildNotSuccess = !SUCCESS.equals(currentBuild.previousBuild?.result)
  197. if(buildNotSuccess || lastBuildNotSuccess) {
  198. stage('Notifiy') {
  199. node {
  200. final def RECIPIENTS = [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']]
  201. def subject = "${buildStatus}: Build ${env.JOB_NAME} ${env.BUILD_NUMBER} status is now ${buildStatus}"
  202. def details = """The build status changed to ${buildStatus}. For details see ${env.BUILD_URL}"""
  203. emailext (
  204. subject: subject,
  205. body: details,
  206. recipientProviders: RECIPIENTS,
  207. to: "$SPRING_SECURITY_TEAM_EMAILS"
  208. )
  209. }
  210. }
  211. }
  212. }