Jenkinsfile 3.3 KB

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