Jenkinsfile 9.7 KB

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