Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to get notified when a Jenkins build has finished?

We use Jenkins as a CI platform. We have integrated it with GitHub, so that whenever I open a PR I can see at the bottom whether a build is running (yellow circle), succeeded (green tick) or failed (red cross). The thing is - the build lasts very long and I have to constantly open the PR and look at the status. I was wondering whether:

1) It is possible, that Jenkins sends an email, when a particular build finishes (but I want to get emails only for builds of my pull requests, not for everybody's PRs)?

2) Maybe the Jenkins bot can write a comment in the PR, which in turn will notify me via GitHub notifications?

Can anybody point me to a resource about how this can be setup?

like image 238
Alexander Popov Avatar asked Apr 21 '17 07:04

Alexander Popov


People also ask

How Jenkins can send email when build pass or failed?

Select “Add post-build action” and Click “E-Mail Notification”. Enter your recipients mail address and select first option “Send e-mail for every unstable build”. Click “Save” button.

How do I email notifications from Jenkins?

Go to the Jenkins home page and click the 'Manage Jenkins' menu option. Then, select the 'Configure System' option. Enter the SMTP server name under 'Email Notification'. Click the 'Advanced' button and then click the checkbox next to the 'Use SMTP Authentication' option.

Is Jenkins have capability of notification mechanism?

Jenkins comes with an out of box facility to add an email notification for a build project. Step 1 − Configuring an SMTP server. Goto Manage Jenkins → Configure System. Go to the E-mail notification section and enter the required SMTP server and user email-suffix details.


Video Answer


1 Answers

If your build is caused by PR on Github, I would advice you to combine 2 things

  1. Get build trigger information (I guess, this info will show you whether you were PR author etc.). Please, check my answer for the case how to get job cause information: How to handle nightly build in Jenkins declarative pipeline
  2. Then, use Email-ext plugin to conditionally send an email (https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin) This will enable you to conditionally send mail to yourself, so in case you are PR author, just send an email.

Also, in case if you will not be able to extract PR author details from build trigger info, consider using https://wiki.jenkins-ci.org/display/JENKINS/GitHub+pull+request+builder+plugin , where Lookup PR detailed information for each PR is supported for sure.

like image 163
Olia Avatar answered Sep 28 '22 00:09

Olia