Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. #!/usr/bin/env groovy
  2.  
  3. node{
  4.  
  5. // vars para deploy, com autenticação do jenkins e hostname do servidor tomcat
  6. def T_USER= "tomcat"
  7. def T_PWD = "secret"
  8. def TOMCAT_HOST = "localhost:8082"
  9.  
  10. stage ('Checkout'){
  11. echo '>> Doing checkout... <<'
  12. checkout([$class: 'GitSCM', branches: [[name: '*/master']], doGenerateSubmoduleConfigurations: false, extensions: [], submoduleCfg: [], userRemoteConfigs: [[credentialsId: '9187dd06-d5f8-4a76-87b2-bec80dd59ade', url: 'https://diogobatista10@bitbucket.org/mei-isep/odsoft-19-20-ncf-g205.git']]])
  13.  
  14. }
  15.  
  16. ws("${env.WORKSPACE}/odsoft/exercise2/component4/cms") {
  17.  
  18. stage ('Build War'){
  19. echo '>> Building and archiving war file... <<'
  20. if(isUnix()){
  21. sh 'gradlew build'
  22. } else {
  23. bat 'gradlew build'
  24. }
  25. archiveArtifacts artifacts: 'build/libs/*.war'
  26. }
  27.  
  28. stage ('Build Javadoc'){
  29. echo '>> Building and archiving javadoc... <<'
  30. if(isUnix()){
  31. sh 'gradlew javadoc'
  32. } else {
  33. bat 'gradlew javadoc'
  34. }
  35. archiveArtifacts artifacts: 'build/docs/javadoc/**/*.*'
  36. }
  37.  
  38.  
  39. stage('Unit Tests') {
  40. echo '>> Running unit tests and publishing report... <<'
  41. if(isUnix()){
  42. sh 'gradlew test jacocoTestReport'
  43. } else {
  44. bat 'gradlew test jacocoTestReport'
  45. }
  46. archiveArtifacts artifacts: 'build/reports/test/**/*, build/reports/jacoco/test/**/*'
  47. publishHTML([allowMissing: false,
  48. alwaysLinkToLastBuild: false,
  49. keepAll: false,
  50. reportDir: 'build/reports/test',
  51. reportFiles: 'index.html',
  52. reportName: 'Unit Test Report',
  53. reportTitles: 'Unit Test Report'])
  54. jacoco execPattern: 'build/jacoco/test.exec'
  55. }
  56.  
  57. stage('Integration Tests') {
  58. echo '>> Running integration tests and publishing report... <<'
  59. if(isUnix()){
  60. sh 'gradlew integrationTest jacocoIntegrationReport'
  61. } else {
  62. bat 'gradlew integrationTest jacocoIntegrationReport'
  63. }
  64. archiveArtifacts artifacts: 'build/reports/test/**/*, build/reports/jacoco/jacocoIntegrationReport/**/*'
  65. publishHTML([allowMissing: false,
  66. alwaysLinkToLastBuild: false,
  67. keepAll: false,
  68. reportDir: 'build/reports/integrationTest',
  69. reportFiles: 'index.html',
  70. reportName: 'Integration Test Report',
  71. reportTitles: 'Integration Test Report'])
  72. jacoco execPattern: 'build/jacoco/integrationTest.exec'
  73. }
  74.  
  75. stage('Mutation Tests') {
  76. echo '>> Running mutation tests and publishing report... <<'
  77. if(isUnix()){
  78. sh 'gradlew pitest'
  79. } else {
  80. bat 'gradlew pitest'
  81. }
  82. archiveArtifacts artifacts: 'build/reports/pitest/**/*'
  83. publishHTML([allowMissing: false,
  84. alwaysLinkToLastBuild: false,
  85. keepAll: false,
  86. reportDir: 'build/reports/pitest',
  87. reportFiles: 'index.html',
  88. reportName: 'Mutation Test Report',
  89. reportTitles: 'Mutation Test Report'])
  90. }
  91.  
  92. stage('System Test') {
  93. echo '>> Deploying application to Tomcat... <<'
  94. // example syntax curl command: curl -u {username}:{password} -T {filename} {FTP_Location}
  95. // example syntax deploy: http://localhost:8080/manager/text/deploy?path=/foo
  96. if(isUnix()){
  97. sh "curl -u ${T_USER}:${T_PWD} -T build/libs/cms-1.0.war '${TOMCAT_HOST}/manager/text/deploy?path=/cms&update=true'"
  98. } else {
  99. bat "curl -u ${T_USER}:${T_PWD} -T build/libs/cms-1.0.war '${TOMCAT_HOST}/manager/text/deploy?path=/cms&update=true'"
  100. }
  101.  
  102. echo '>> Running automatic smoke test <<'
  103. def smokeTestResult
  104. // example syntax curl command: curl -sL -w "%{http_code}" "http://www.google.com/" -o /dev/null
  105. if(isUnix()){
  106. smokeTestResult = sh "curl -sL -w "%{http_code}" 'http://${TOMCAT_HOST}/cms/' -o /dev/null"
  107. } else {
  108. smokeTestResult = bat "curl -sL -w "%{http_code}" 'http://${TOMCAT_HOST}/cms/' -o /dev/null"
  109. }
  110. if(smokeTestResult == 200){
  111. echo '>> Smoke test passed! <<'
  112. } else {
  113. echo '>> Smoke test failed. Expected response status code 200 but got ${smokeTestResult} instead'
  114. }
  115. }
  116.  
  117. stage("UI Acceptance Manual Tests "){
  118. emailext body: "Build#${BUILD_NUMBER}-${currentBuild.currentResult}\n More info at: ${BUILD_URL}",
  119. recipientProviders: [[$class: 'RequesterRecipientProvider']],
  120. subject: "Jenkins Build ${currentBuild.currentResult}"
  121. input 'Conclude Build?'
  122.  
  123. }
  124. stage("Continuous Integration Feedback "){
  125. bat("git tag -a Build#${BUILD_NUMBER}-${currentBuild.currentResult} -m 'Jenkins'")
  126. bat("git push https://diogobatista10@bitbucket.org/mei-isep/odsoft-19-20-ncf-g205.git --tags")
  127.  
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement