Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of individuals who broke the build in Jenkins Pipeline

Is there a way to retrieve a list of individuals who broke the build in Jenkins Pipeline, just like the mailer plugin apparently does to send out a mail to those involved?

like image 597
Jazzschmidt Avatar asked Nov 20 '25 01:11

Jazzschmidt


1 Answers

I've found one possible way, though it is somewhat limited to the amount of builds that are being kept. By iterating over the previousBuild hierarchy and their change logs, this may be a solution:

def getAuthors(def build) {
    def userIds = []

    build.changeSets.each { hudson.scm.SubversionChangeLogSet changeLogSet ->
        userIds += changeLogSet.collect { it.author.id }
    }

    userIds.unique()
}

def getIndividualsWhoBrokeTheBuild() {
    def userIds = []

    for(def build = currentBuild; build.result != 'SUCCESS'; build = build.previousBuild) {
        userIds += getAuthors(build)
    }

    userIds.unique()
}

Suppose a job keeps only five builds, this won't return the original felon, if it was broken more than five builds before.

like image 92
Jazzschmidt Avatar answered Nov 22 '25 02:11

Jazzschmidt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!