How to get criminals or committers inside a Jenkins workflow with one or more SCM

Is it possible to access information about committers and / or perpetrators of a Jenkins workflow job when checking one or more SCMs (either using checkout () or other SCM steps such as git / svn)?

The goal is to use this information to notify committers and / or perpetrators of job status, for example, in the mail step.

A small example of a workflow definition:

 node { // checkout from one or more SCMs, eg git url: '<URL>' checkout([$class:...]) ... // how can we know about committers or culprits at this point? $committers = ?? // send a mail to committers or culprits mail to: '$committers', subject: 'JENKINS', body: '<information about the job status>' } 

How can this be adapted to produce a collection of committers after running SCM steps?

Edit: I am currently working with Jenkins version 1.596.2 and Workflow: Aggregator version 1.6, and it seems to be an open issue in JENKINS-24141

+6
source share
7 answers

As you have found, pending JENKINS-24141 this is not supported. Changes to the Jenkins core are required.

+2
source

Now it is possible using the email-ext plugin.

 def to = emailextrecipients([[$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider'], [$class: 'RequesterRecipientProvider']]) if (to != null && !to.isEmpty()) { mail to: to, subject: "JENKINS", body: "See ${env.BUILD_URL}" } 

However, if you just want to send an error message, you can use Mailer (based on examples of the ext-email pipeline ):

 step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: emailextrecipients([[$class: 'CulpritsRecipientProvider'], [$class: 'RequesterRecipientProvider']])]) 
+4
source

You can get xml information for a job in which you will find the name of the person who made the change, along with commit messages.

 http://<Jenkins URL>:<Port Number>/job/<Jobname>/<BuildNumber>/api/xml? 

Give it in the browser. Find the "user". You can send this information to a text file for processing.

+2
source

Using groovy in a pipeline script:

 @NonCPS // Necessary to allow .each to work. def changelist() { def changes = "" currentBuild.changeSets.each { set -> set.each { entry -> changes += "${entry.commitId} by ${entry.author.fullName}\n" } } changes } 
+2
source

It seems that this function was implemented inside the email-ext plugin, but the author forgot to document how we should use it.

Please check https://issues.jenkins-ci.org/browse/JENKINS-34763 - and add a comment there, asking for an example. I have already done.

+1
source

similar to answer from @szym, but without @NonCPS required:

def authors = currentBuild.changeSets.collectMany { it.toList().collect { it.author } }.unique()

0
source

If you want to notify the perpetrators who violated the assembly, you do not need any checks, use the jenkins email plugin. This plugin gives you the ability to send letters to committers between the last good build and the current broken build.

If you use the “Editable Email Notification Plugin”, you will be able to send mail to the culprit.

If you use the plugin for email, you get the option "Send individual emails to people who have broken the assembly."

-2
source

Source: https://habr.com/ru/post/987752/


All Articles