Reputation: 31
How to integrate the bitbucket repository to Jenkins and get it executed every 5 mins. get an email notification for every failed builds upfront and get a notification of all passed build every hour. Use Case
Upvotes: 0
Views: 1207
Reputation: 16564
You need to combine:
import hudson.model.*
node {
def nowDateInMilliseconds = new Date().getTime();
def job = Jenkins.instance.getItemByFullName('my_job-full_name');
def lastHourSucessBuild = [];
for(def build in job.builds){
if (build.result!=hudson.model.Result.SUCCESS) continue;
def lastSuccessBuildDateOnMillis = build.getTime().getTime();
long diff = nowDateInMilliseconds - lastSuccessBuildDateOnMillis;
long diffMinutes = diff / (60 * 1000);
println build.number+" : Time in minutes: " + diffMinutes
if(diffMinutes<60)lastHourSucessBuild.add(build.number)
}
println "Last hour success builds: " + lastHourSucessBuild
emailext (
subject: "Last hour success builds",
body: "Last hour success builds: " + lastHourSucessBuild,
to: "[email protected]"
)
}
Full job config here
I advice to try bit by bit:
Only if you achieve these demos, combine all in one scripted pipeline ;)
Upvotes: 1