Advertisement
Guest User

Untitled

a guest
Jan 8th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.79 KB | None | 0 0
  1. import com.tikal.jenkins.plugins.multijob.*
  2. import hudson.*
  3. import hudson.model.*
  4. import hudson.plugins.git.*
  5. import hudson.slaves.*
  6. import hudson.tasks.*
  7.  
  8. def ln = System.getProperty('line.separator')
  9. println "---------------Groovy Changelog script Started---------------$ln"
  10.  
  11. def lastSuccesfulBuild = build.previousNotFailedBuild
  12. def failed = build.result != hudson.model.Result.SUCCESS
  13.  
  14. println "Last Succesful Build: ${lastSuccesfulBuild}"
  15. println "Current Build Result, is failed?: ${failed}"
  16.  
  17.  
  18. def currResult = build.result
  19. def prevResult = build.previousBuild?.result ?: null
  20.  
  21. def consecutiveSuccess = currResult == hudson.model.Result.SUCCESS && prevResult == hudson.model.Result.SUCCESS
  22.  
  23. def builds = []
  24. def changes = []
  25. def count = 0
  26.  
  27.  
  28.  
  29. if (consecutiveSuccess) {
  30.     builds << build
  31.     def changeItems = build.changeSet.items
  32.     count += changeItems.length
  33.     changes += changeItems as List
  34. } else {
  35.     while (lastSuccesfulBuild) {
  36.         builds << lastSuccesfulBuild
  37.         def changeSet = lastSuccesfulBuild.changeSet
  38.         if (!changeSet.emptySet) {
  39.             def changeItems = lastSuccesfulBuild.changeSet.items
  40.             count += changeItems.length
  41.             changes += changeItems as List
  42.         }
  43.         lastSuccesfulBuild = lastSuccesfulBuild.nextBuild
  44.     }
  45. }
  46.  
  47. def changesString = ""
  48. if (count ==0){
  49.    changesString += "No changes"
  50. } else {
  51.     changes.each { item ->
  52.     changesString += ("$item.comment by $item.author;".replaceAll("$ln"," "))
  53.     }
  54. }
  55. println "$changesString"
  56.  
  57. workspace = build.environment.get("WORKSPACE");
  58. if(build.workspace.isRemote()){
  59. channel = build.workspace.channel
  60. }
  61. def props = new hudson.FilePath(channel,"${workspace}/dynamic.properties")
  62. props.write("calculatedchanges=$changesString",null)
  63.  
  64. println "---------------Groovy Changelog script Finished---------------$ln"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement