0

I have set a rule in the outlook that

apply this rule after arrives
with "xyz" in the subject
and move it to the "buildme"

folder "buildme" was created as a data file at

C:\Users\myid\AppData\Local\Microsoft\Outlook\builme.pst

In Jenkin under the project, I created build trigger as below:

[FSTrigger] - Monitor files
File Path: C:\Users\myid\AppData\Local\Microsoft\Outlook\builme.pst
Schedule: 55 * * * 1-5

I sent an email with "xyz" in the subject line. the email then was moved to the "buildme" folder, thus the file C:\Users\myid\AppData\Local\Microsoft\Outlook\builme.pst gets update at, say at "3/24/2016 11:24 AM".

At 11:55 AM, the build was correctly triggered.

However, at 12:55 PM, another build was triggered again, unexpectedly, although there was no new email sent. this goes on for every hour.

What I did wrong?

Heinz
  • 913
  • 4
  • 12
  • 22

2 Answers2

1

Outlook probably touched the file in some way, modifying some timestamp which leads FSTrigger to start the build.

For the sake of robustness i suggest to not rely on monitoring the outlook folder file for changes, as it might change unexpectedly. Instead modify your rules to directly trigger the build job on the jenkins server.

I.e. pseudocodeish: IF subject CONTAINS keyword ACCESS jenkinsurl_that_starts_build

How to run a script based on outlook rules seems to be layed out here and information on how to trigger a build via http request on a jenkins url is explained here

You could even extend it in the future to pass parameters from your email to your build, as these can be set via url access too. More info on this here, section Launching a build with parameters

Community
  • 1
  • 1
Dominik Gebhart
  • 2,980
  • 1
  • 16
  • 28
  • Thanks Dominik. I tried to issue a HTTP request, but it seems not trigger a build. Here is what I did:
    In the VBA script, add the code:`code` Set objHTTP = CreateObject("Microsoft.XMLHTTP") URL = "http://56.xxx.xxx.xxx:8080/job/testenv/build?token=go" objHTTP.Open "POST", URL, False objHTTP.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" objHTTP.Send (""). After execution of this code, no build was triggered.
    – Heinz Mar 28 '16 at 16:38
  • Try to verify first that the url is indeed correct by putting it into i.e. Firefox. Stuff needs to be properly urlescaped (firefox does this automatically), token you only need when you have set it in your build options. – Dominik Gebhart Mar 28 '16 at 17:24
  • 1
    After changed "56.xxx.xxx.xxx:8080/job/testenv/build?token=go" to "56.xxx.xxx.xxx:8080/job/testenv/buildWithParameters?token=go", it works – Heinz Mar 28 '16 at 17:41
1

I changed the rule to:

apply this rule after arrives 
with "xyz" in the subject 
run projetcs.ThisOutlookSession.WriteStringToFile

and the VBA script:

Sub WriteStringToFile1(MyMail As MailItem)
    Const FILEPATH = "c:\buildtrigger\testtest.txt"

    Dim strSubject As String
    Dim strSender As String
    Dim strText As String
    Dim strID As String
    Dim objMail As Outlook.MailItem

    strID = MyMail.EntryID
    Set objMail = Application.Session.GetItemFromID(strID)

    strSubject = objMail.Subject
    strSender = objMail.SenderName


    Open FILEPATH For Output As 1
    Print #1, "SET XYZ = " & strSubject & ";" & strSender & "--" & Now
    Close #1

End Sub

this VBA script will write one line to testtest.txt.

In Jenkins, create a build trigger:

[FSTrigger] - Monitor folder
Path = c:\buildtrigger
Includes = testtest.txt
Exclude check lastModification date = true
Exclude check content = false
Exclude check fewer or more files = true
schedule: * * * * 1-5

Send email with xyz in the subject, a build will be successfully triggered, and no build triggered when no email was received.

As a side note, it looks like the timestamp of the file is modified by FSTrigger, not by Outlook or Windows.

Heinz
  • 913
  • 4
  • 12
  • 22