Our legacy site: www.webwob.com   

An email interface to Jenkins and automation. Part 1

It would be great if our automated jobs could send out emails with status changes OR job completion status. This 'part 1' covers the setup for that functionality. Part 2 (to follow) will cover initiating jobs from a received email. (I have got part 2 working already but it's not really a commercial solution for job control, so do bear this in mind. It is better to use a proper messaging queue technique.)

     LoadRunner CI/CD      *_LR_CI_*      LR_CI_+      Email_out      Email_in      Cookies 1      TUTORIAL      sprintf      debug      VUgen      Kill -9      disk space      AWS S3      dig (DNS++)      substitute      curl with timings      LR_Jenkins_graphs     

    

Configure Jenkins to send out an email on job complete

I will intersperse screenshots in this page to make things clearer and print code where required

Areas covered on this page

Step 1: Setup a local mail server

Step 2: Setting up the Jenkins main configuration

Step 3: Setting up Jenkins job email control


Step 1: Setup a local mail server

Screen shots for: Setting up domain, adding local email account, SMTP relayer (if needed), logging and debugging

Start up and add a Domain:
Install hMailServer, found here at the time of print: www.hmailserver.com. Follow instructions and add a hostname and sort out the logging in to the App. Once in, add a domain and a local account as shown in the first three screenshots below:
hMailServer         
        
Setup domain         
        
Create local email address         
        
SMTP Relayer
This defines how we are going to send emails. At home, I use my standard email server BUT at work, because we are in a closed AWS environment, I didn't need to set this up at all. I could just use the hMailServer itself to send out the emails. HOWEVER, I did need to use a real email address in the JENKINS SETUP (which will be shown next) - I COULDN'T USE 'admin@loadrunner' for the sending email address. AND, the sending email address HAS to MATCH the SMTP relayer logon info IF you are using that feature:
SMTP Relayer         
        
Logging
This setting is important because typically you are going to run into issues to start with and this feature allows you to see inside the mail server and get all the info you need to fix it:
Run on master         
        
Pressing the show logs button gives:
Turn on logging         
        
Inside a typical log file
Typical log file         
NOTE: my hMailServer service (on my home PC) runs with this command:

    
"C:\Program Files (x86)\hMailServer\Bin\hMailServer.exe" RunAsService



Step 2: Setting up the Jenkins main configuration

Click on 'Manage Jenkins' and then select 'Configure system':
Manage Jenkins         
Adjust the following settings
There are a lot of settings in this page. We mainly want to tackle the email configuration, but there are a couple of other things to consider along the way, such as the Jenkins URL (which is sent out in our emails to construct URLs for the results etc.). And even the system admin e-mail address will want checking to fit in with our new services.

Jenkins URL and system Admin email address:         
email address for sys admin         
        

Default email suffix, default recipients and reply-to list:         
default emails         
        
Use SMTP Authentication:
Turn this on and use the username and password as you've setup above in the hMailServer account. NOTE: on some of our boxes I have set this up on several email plugins, depending on what we want to use on particular projects. Just follow the same ideas in each plugin. It does say in the help, if you leave the SMTP server blank, it will default to the local machine, which is what we want here:         
default emails         
        
Press the Default Triggers button:
default emails         
        
And select 'Always' or 'failures - Any', depending on your needs
default emails         
        
There are some settings under the 'Advanced' button as well, determining which groups of users get which emails etc. Worth looking at for your own requirements.

Step 3: Setting up Jenkins job email control

The Editable Email Notification
There are a few email plugins for Jenkins Jobs but I have found this one to suffice for my needs. Add this as a post-build action. Attaching the build log does make the email very useful for your userbase to immediatly see what is going on (I typically forward the email onto my dev team automatically from my work email system):
hMailServer

Setup domain         
'Advanced Settings' includes the following extra configuration:
Create local email address         
And then the 'Advanced' button lets you define the recipients list etc. if required:
Create local email address