Guest User

Untitled

a guest
Feb 12th, 2018
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. pipeline {
  2.  
  3. agent {
  4. label 'BUILD' //Executed on agents with this label
  5. }
  6.  
  7. triggers {
  8. pollSCM('* * * * *') //Polls every minute. If your git repo supports web-hooks this is not necessary.
  9. }
  10.  
  11. environment {
  12. NO_CHROME_OPTS = "TRUE" //Environment variables
  13. }
  14.  
  15. options {
  16. disableConcurrentBuilds()
  17. }
  18.  
  19. stages {
  20. stage('Checkout') {
  21. steps {
  22. checkout scm //Checks out the SCM where the Jenkinsfile is located
  23. addJFrogCredentialsToGradlePropertiesFile() //custom groovy method
  24. }
  25. }
  26. stage('Frontend Static Code Analysis') { //stages are displayed in Jenkins UI
  27. steps {
  28. sshagent(['git']) { //provide SSH key for a git repo from another project necessary for the build, "git" is configured in Jenkins
  29. script {
  30. try {
  31. sh './gradlew tslint --no-daemon'
  32. } finally { //make checkstyle results accessible to user
  33. checkstyle canComputeNew: false, defaultEncoding: '', healthy: '', pattern: 'frontend/tslint-result.xml', unHealthy: ''
  34. }
  35. }
  36. }
  37. }
  38. }
  39. stage('Frontend Unit Tests') {
  40. steps {
  41. sshagent(['git']) {
  42. script {
  43. try {
  44. sh './gradlew cleanFrontendTest --no-daemon'
  45. sh './gradlew frontendUnitTest --no-daemon'
  46. } finally {
  47. junit 'frontend/test/karma-result.xml' //make junit report accessible to user
  48. }
  49. }
  50. }
  51. }
  52. }
  53. stage('Unit & Integration Tests') {
  54. steps {
  55. script {
  56. try {
  57. sh './gradlew clean test --no-daemon'
  58. } finally {
  59. junit '**/build/test-results/test/*.xml'
  60. }
  61. }
  62. }
  63. }
  64. stage('End 2 End Tests') {
  65. steps {
  66. script {
  67. try {
  68. sh './gradlew e2e --no-daemon'
  69. } finally {
  70. junit '**/e2e-results/junit-formatted/*.xml'
  71. publishHTML([allowMissing: false, alwaysLinkToLastBuild: false, keepAll: false, reportDir: 'frontend/test/e2e-results/html-formatted/', reportFiles: 'htmlReport.html', reportName: 'End 2 End Test Report', reportTitles: ''])
  72. } //make the HTML results of the e2e tests available to user
  73. }
  74. }
  75. }
  76. stage('Publish Artifact') {
  77. steps {
  78. sh './gradlew publish --no-daemon'
  79. }
  80. }
  81. stage('SonarQube Analysis') {
  82. steps {
  83. script {
  84. scannerHome = tool 'sonarscanner'
  85. }
  86. withSonarQubeEnv('sonar') {
  87. sh "${scannerHome}/bin/sonar-scanner"
  88. }
  89. }
  90. }
  91. }
  92. post {
  93. always { //If the build fails, send an email to the last person(s) to commit since the last green build
  94. step([$class : 'Mailer',
  95. notifyEveryUnstableBuild: true,
  96. recipients : [emailextrecipients([[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']])].join(' ')])
  97. }
  98. }
  99. }
  100.  
  101. private void addJFrogCredentialsToGradlePropertiesFile() { //Write jFrog credentials to gradle.properties file
  102. withCredentials([usernamePassword(credentialsId: 'jFrog', usernameVariable: 'JFROG_USER', passwordVariable: 'JFROG_PASSWORD')]) {
  103. sh "rm -f ~/.gradle/gradle.properties"
  104. sh "echo jFrogUser=$JFROG_USER >> ~/.gradle/gradle.properties"
  105. sh "echo jFrogPassword=$JFROG_PASSWORD >> ~/.gradle/gradle.properties"
  106. }
  107. }
Add Comment
Please, Sign In to add comment