Jenkinsfile 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. try {
  10. parallel check: {
  11. stage('Check') {
  12. node {
  13. checkout scm
  14. try {
  15. sh "./gradlew clean check --refresh-dependencies --no-daemon --stacktrace"
  16. } catch(Exception e) {
  17. currentBuild.result = 'FAILED: check'
  18. throw e
  19. } finally {
  20. junit '**/build/*-results/*.xml'
  21. }
  22. }
  23. }
  24. },
  25. sonar: {
  26. stage('Sonar') {
  27. node {
  28. checkout scm
  29. withCredentials([string(credentialsId: 'spring-sonar.login', variable: 'SONAR_LOGIN')]) {
  30. try {
  31. if ("master" == env.BRANCH_NAME) {
  32. sh "./gradlew sonarqube -PexcludeProjects='**/samples/**' -Dsonar.host.url=$SPRING_SONAR_HOST_URL -Dsonar.login=$SONAR_LOGIN --refresh-dependencies --no-daemon --stacktrace"
  33. } else {
  34. sh "./gradlew sonarqube -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"
  35. }
  36. } catch(Exception e) {
  37. currentBuild.result = 'FAILED: sonar'
  38. throw e
  39. }
  40. }
  41. }
  42. }
  43. }
  44. if(currentBuild.result == 'SUCCESS') {
  45. parallel artifacts: {
  46. stage('Deploy Artifacts') {
  47. node {
  48. checkout scm
  49. withCredentials([file(credentialsId: 'spring-signing-secring.gpg', variable: 'SIGNING_KEYRING_FILE')]) {
  50. withCredentials([string(credentialsId: 'spring-gpg-passphrase', variable: 'SIGNING_PASSWORD')]) {
  51. withCredentials([usernamePassword(credentialsId: 'oss-token', passwordVariable: 'OSSRH_PASSWORD', usernameVariable: 'OSSRH_USERNAME')]) {
  52. withCredentials([usernamePassword(credentialsId: '02bd1690-b54f-4c9f-819d-a77cb7a9822c', usernameVariable: 'ARTIFACTORY_USERNAME', passwordVariable: 'ARTIFACTORY_PASSWORD')]) {
  53. 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"
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. },
  61. docs: {
  62. stage('Deploy Docs') {
  63. node {
  64. checkout scm
  65. withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
  66. sh "./gradlew deployDocs -PdeployDocsSshKeyPath=$DEPLOY_SSH_KEY -PdeployDocsSshUsername=$SPRING_DOCS_USERNAME --refresh-dependencies --no-daemon --stacktrace"
  67. }
  68. }
  69. }
  70. },
  71. schema: {
  72. stage('Deploy Schema') {
  73. node {
  74. checkout scm
  75. withCredentials([file(credentialsId: 'docs.spring.io-jenkins_private_ssh_key', variable: 'DEPLOY_SSH_KEY')]) {
  76. sh "./gradlew deploySchema -PdeployDocsSshKeyPath=$DEPLOY_SSH_KEY -PdeployDocsSshUsername=$SPRING_DOCS_USERNAME --refresh-dependencies --no-daemon --stacktrace"
  77. }
  78. }
  79. }
  80. }
  81. }
  82. } finally {
  83. def buildStatus = currentBuild.result
  84. def buildNotSuccess = !SUCCESS.equals(buildStatus)
  85. def lastBuildNotSuccess = !SUCCESS.equals(currentBuild.previousBuild?.result)
  86. if(buildNotSuccess || lastBuildNotSuccess) {
  87. stage('Notifiy') {
  88. node {
  89. final def RECIPIENTS = [[$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']]
  90. def subject = "${buildStatus}: Build ${env.JOB_NAME} ${env.BUILD_NUMBER} status is now ${buildStatus}"
  91. def details = """The build status changed to ${buildStatus}. For details see ${env.BUILD_URL}"""
  92. emailext (
  93. subject: subject,
  94. body: details,
  95. recipientProviders: RECIPIENTS,
  96. to: "$SPRING_SECURITY_TEAM_EMAILS"
  97. )
  98. }
  99. }
  100. }
  101. }