Groovy Postbuild in Jenkins, parsing the log for strings and counting them

前端 未结 3 591
暖寄归人
暖寄归人 2021-01-14 22:44

I am new to Groovy and am trying to set up a postbuild in Jenkins that allows me to count strings and determine if the build succeeded by how many the count returns at the e

相关标签:
3条回答
  • 2021-01-14 23:36

    You have statements directly inside your class, without being in a method, which is not allowed in Java/Groovy. Since this is Groovy, you can run this as a script without the class at all, or put the offending code (the if statement) inside a method and call the method.

    0 讨论(0)
  • 2021-01-14 23:38

    Perhaps you're missing a closing }

    def JobCount = list.count {it.startsWith("====") && it.contains("COMPLETE")}
    
    0 讨论(0)
  • 2021-01-14 23:43

    manager.build.logFile.text returns the whole file text as String.

    What you need is readLines():

    def list = manager.build.logFile.readLines()
    def JobCount = list.count {it.startsWith("====") && it.contains("COMPLETE")}
    

    and of course as mentioned below, the Jenkins Groovy Postbuild plugin runs Groovy scripts, so you will have get rid of the enclosing class declaration (Main)

    0 讨论(0)
提交回复
热议问题