Jenkinsfile 9.8 KB

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