0

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

  1. Create an automation test for a few page URLs - Done
  2. Execute it every 5 mins (Schedule with Jenkins) - Done
  3. Send an email as soon as any build got fail - Done
  4. Send an email every 1 hour for all passed build in last one hours (exclude the fail one) - Need help on this
  • Too much questions in one question. Please update your question to avoid down-votes. Did you research something? Show us your effort. – JRichardsz May 05 '23 at 05:28
  • Thanks !! Use Case wheere I need help - Send an email every 1 hour for all passed build in last one hours (exclude the fail one) - Need help on this – Snehil Mishra May 05 '23 at 05:47

1 Answers1

1

You need to combine:

Every hour trigger

enter image description here

Query builds with groovy + mail

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: "test@gmail.com"
    )
}

Full job config here

Advices

I advice to try bit by bit:

  • config the emailext and send a mail as demo
  • config the build trigger and print a message every minute

Only if you achieve these demos, combine all in one scripted pipeline ;)

JRichardsz
  • 14,356
  • 6
  • 59
  • 94