Our legacy site: www.webwob.com   

An email interface to Jenkins and automation. Part 2

Trigger our automated jobs simply after receiving an email! This 'part 2' covers the setup for this functionality. See Part 1 for sending emails out from our Jenkins jobs on completion.

     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 Received emails to trigger Jenkins jobs

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 email client

Step 2: Add an email filter plugin

Step 3: Control the running of Jenkins jobs

Addendum: setting up outlook email filters

Step 1: Setup a local email client

Screen shots for: Setting up a client, adding an email filter, running a Jenkins job (dos) by batch file

Start up and add a mailbox:
This page will take you through my own setup using Thunderbird, but there are many email clients out there with similar facilities so feel free to use your own software choice and just follow the general guidelines below. (I may be able to grab screenshots from our office Outlook, which does have similar features, but our workstations are locked down so actually, I can't use it in this case)

Install ThunderBird, found here at the time of print: www.mozilla.org. Follow instructions and setup a connection to your preferred imap mailbox (I use one of my website's standard facilities):

Step 2: Add an email filter plugin

Add the email filters plugin called 'FiltaQuilla':
Setup domain
Set your main preferences. I do find the 'Run File' option the most useful for my approach outlined below:
Create local email address         
In the main Thunderbird window, go to Tools, Message Filters and press the 'New' button. This presents you with the 'Filters Rules' options (shown below). To keep things fairly secure and locked down by the performance test analyst, I provide simple rules that say for example: if a message appears from 'my_user@my_company' AND the subject is 'run my Performance Job' THEN, run the file I specify, which contains all the instructions:
SMTP Relayer         

Step 3: Control the running of Jenkins jobs

Run a batch file
To keep my setup secure, I keep the details of my jobs on the box itself and just give users a message to send to run the job. So the way in which I run the job is kept separate from the email itself. This certainly feels more secure and of course I can easily turn job access on and off myself as required.
C:\cygwin\bin\bash -c "wget --no-cookies --header=\"Authorization: Basic bmdvZGZyZXl***************s6VGVsZXBob25lMDI=\" --post-data ' '"
The batch job I run can of course be tailored to my individual jobs that I want to run on this box. Above is an example of a Jenkins job, including the proper log in required. Notice I do tend to use cygwin as BASH gives me more control on all sorts of job activities.
In fact, when you setup a default email filter rule using the 'FiltaQuilla' plugin, you typically get a 'Run File' line such as:

And then you can make use of the command line arguments as shown below. Note the date time stamp is added to the log file for our records. I am not actually using the command line arguments in earnest here, but of course you can do so just by editing the batch file as required. And there are other arguments you can pass down to the script, see the 'FiltaQuilla' user manual for details:

        rem NOTE DOWN the run time:
        echo %date% %time% >> c:\loadrunner\log.txt
        echo first parameter is %1 >> c:\loadrunner\log.txt
        echo second parameter is %2 >> c:\loadrunner\log.txt
        echo --- about to run allweb --- >> c:\loadrunner\log.txt
        echo ------ >> c:\loadrunner\log.txt
        C:\cygwin\bin\bash c:\loadrunner\pipeline_allweb.sh

Final Note

Because I have already setup my Jenkins jobs to send emails out on completion, we can now cascade our jobs if required, using the approach above to trigger new jobs based on the Jenkins emails, lets say if we get a 'Passed' subject email from a particular Jenkins job, then trigger a different box to run the next job inline. etc. etc.


Because all our boxes (in our case) are watching the same IMAP mail box, ALL boxes see the job status as it rolls, so we do actually have our own (cheap, non-commercial) instant messaging queue system! This is NOT recommended for proper commercial systems, by the way.


Outlook can be setup as well, to run commands on receiving certain emails. I've grabbed some screenshots to show roughly how you can do this:
SMTP Relayer         
SMTP Relayer         
Press 'Advanced Options' and select 'start application':         
SMTP Relayer         
Browse to your batch file as shown above with Thunderbird:         
SMTP Relayer