mailto:jenkins,subject:test case1, case2 on

mailto:jenkins,subject:test case1, case2 on

So this is something we thought of

– email Jenkins
– to run one or more jobs
– against one of our deployed staging apps(given base_url)

We wrote a mail_watcher.rb, which periodically reads such emails, and rewrite <JENKINS_CHECKS_DIR>/<test_case_name>.checks files adding parameters to be passed on to the test case. In this case it is BASE_URL=. And all we know that we could make Jenkins

1. watch files getting modified
2. use file contents(key=val), as paramters further to be used or passed on to the job exec

Ohh, wait, I did not know how could Jenkins read parameters from a given key=val file and pass it on further. We actaully wrote another shell script which runs as the first step of every job and reads the testcase_name.checks file and set ENV variables like for example BASE_URL.

So in case of subject:test testcase1 on

– mail watcher will write testcase1.checks file with BASE_URL=
– shell script will set ENV variable BASE_URL=

Following is the mail watcher that we simply run to be able to get Jenkins job triggered.

require 'net/imap'
class MailWatcher
Server = ''
Username = ''
Password = ''
Folder = 'INBOX'
PollingInterval = 60
CheckFileLocation = "#{File.dirname(__FILE__)}/../../tmp/checks/"
def fetch
@imap = Server, 993, true
@imap.login Username, Password Folder["NOT", "SEEN"]).each do |message_id|
env = @imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
@subject = env.subject
return unless @subject.match(/^test .+/)
test_cases.each do |test_case_name|"#{CheckFileLocation}#{test_case_name}.check",'w') { |file| file.puts base_url }
mark_delete message_id
def start_watching
while(1) do
sleep PollingInterval
def base_url
@base_url ||= "base_url=#{@subject.match(/ on (https?\:\/\/[a-z\.]+)$/)[1]}" rescue 'base_url='
def test_cases
@test_cases = @subject.split(' on http').first[5..-1].strip.split(',').collect{ |test_case| test_case.strip.gsub(' ','_')}
def mark_delete message_id, "+FLAGS", [:Seen]), "+FLAGS", [:Deleted])

view raw


hosted with ❤ by GitHub

Now any of us teammates, can anytime send an email and get a test case executed. In addition we are as well generating a detailed report email for each job-run that gets published on a Google group. We do have our own custom, half-baked, reporting mechanism(ruby code), which we want to compile the job-execution-report email for each testcase/job executed.

Example reports

subject: testcase1 failed.
body: <Jenkins console output>

subject: rspec 231 passed, 2 failed.
body: <Jenkins console output>

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s