"cancel" variable in groovy script not working in Jenkins Email-ext plugin -
i'm having issue want cancel sending email when job gets fixed state unstable state. if job failing got fixed, want send message. if job unstable (tests not passing) , gets fixed, don't send email. might job marked unstable after has been in failure state. when goes success (i.e. fixed) want email in case. can see cases in code below.
my problem when set variable cancel
true
definition[1] should cancel email, doesn't. email gets sent every time. of course i'm using triggers "failure", "still failing" , "fixed".
jenkins version: 1.533. email-ext version: 2.37.2.2
// goal of script block sending 'fixed' message // when status goes 'unstable' 'success' // // these cases (where f=failure, u=unstable, s=success) // s - s : no msg (previous state: s, current state: s) // f - s : msg // s - u ... u - s : no msg <-- 1 need avoid sending email // f - u ... u - s : msg logger.println("entering pre-send script") // variable definitions def keepgoing= true def cancelemail = false // object current job job = hudson.model.hudson.instance.getitem("incr-build-master") // current build number buildnumber = build.getnumber() logger.println("current build number: " + buildnumber) // if build failed or unstable don't anything, // specific triggers should take care of messages if (build.result.tostring().equals("success")) { logger.println("build successful. procesing...") while( keepgoing ) { // number of next past build pastbuild = job.getbuildbynumber(--buildnumber) buildresult = pastbuild.result.tostring() switch ( buildresult ) { case "success": // if previous non-unstable build successful // don't send 'fixed' message cancelemail = true keepgoing = false logger.println("cancel sending email") break case "failure": // here exit, send 'fixed' message keepgoing = false logger.println("send email") break case "unstable": // let keep looking until find previous build // either 'success' or 'failure* logger.println("build " + buildnumber + " unstable") break default: logger.println("error in script: result string wrong - " + buildresult) return } } } logger.println("emailed canceled?: " + cancelemail) cancel=cancelemail logger.println("exiting pre-send script")
[1] icon: "you may cancel sending email setting boolean variable "cancel" true."
i encountered same problem , found solution in couple of days.
"cancel" works when used in last line of code.
this cancel build:
changed = false files = 5 cancel = true
this not:
changed = false cancel = true files = 5
and do cancel:
changed = false files = 5 if (files > 2) { cancel = true }
i hope save time somebody.
Comments
Post a Comment