Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get culprits or committers inside a Jenkins workflow with one or more SCMs

Is it possible to access information about committers and/or culprits of a Jenkins workflow job when checking out from one or more SCMs (either via checkout() or other SCM steps like git/svn)?

The intention is to use that information to notify committers and/or culprits about the job status, for example in a mail step.

A small example of a workflow definition:

node {
  // checkout from one or more SCMs, e.g.
  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 could this be adapted to get a collection of the committers after running the SCM steps?

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

like image 531
DenizU Avatar asked May 22 '15 13:05

DenizU


People also ask

What is culprits Jenkins?

Culprits: Sends email to the list of users who committed a change since the last non-broken build till now.

What is SCM in Jenkins pipeline?

In Jenkins, SCM stands for "Source Code Management". This option instructs Jenkins to obtain your Pipeline from Source Control Management (SCM), which will be your locally cloned Git repository.

How do I create a pipeline script in Jenkins?

To create a simple pipeline from the Jenkins interface, perform the following steps: Click New Item on your Jenkins home page, enter a name for your (pipeline) job, select Pipeline, and click OK. In the Script text area of the configuration screen, enter your pipeline syntax.


1 Answers

This is now 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 email on failures, you may want to use Mailer (based on the email-ext pipeline examples):

step([$class: 'Mailer',
      notifyEveryUnstableBuild: true,
      recipients: emailextrecipients([[$class: 'CulpritsRecipientProvider'],
                                      [$class: 'RequesterRecipientProvider']])])
like image 72
Wilfred Hughes Avatar answered Oct 25 '22 01:10

Wilfred Hughes