Your suggestion launched me on a track that worked.  But I got it all wrong 
because I did not understand all I could do with a groovy script.

I upgraded my build script (Python based and commited in the sources) to 
use SVN_URL & SVN_REVISION to pull the commit log from Subversion.  The 
build script then parses the commit log to find the bug number.  The bug 
number is printed to stdout and it ends up in the Jenkins build log.

Then I wrote a pre-send groovy script for email-ext to grep the build log 
for the build number.  Once I have the build number, the email subject is 
updated.  Here is my script:

--snip--
import java.util.regex.Pattern;
import java.util.regex.Matcher;
try {
  log = build.getLog()
  def pattern = 
Pattern.compile(/7928DEC7-17B5-40a1-B094-282AE167178F\s+(\S+)\s+(.*)/)
  def matcher = pattern.matcher(log)
  def found = matcher.find()
  if ( found ) {
    def job = build.getParent().name
    def number = matcher.group(1)
    def summary = matcher.group(2)
    def subject = summary
    if ( number != 'N/A' ) {
      subject = "${summary} (bug ${number})"
    }
    msg.setSubject("[Build ${job}] ${subject}")
  }
} catch(e) {
  msg.setContent(e.toString(),'text/plain')
}
--end snip--

For people who are new to this, some pseudo-code and explanations:

The 'build' and 'msg' objects are prepopulated when the script is launched. 
 We get the log from 'build'.  Then we use a java.util.regex.Matcher to 
locate the build number in the log text.  Finally, the 'msg' object (a 
plain Java MimeMessage object) is modified with a new subject.

This is crazy.  Now my build script (commited along the sources) is 
performing a task it should not care about: parsing a SVN commit.  The 
better solution would be to have the pre-send groovy script do all that. 
 It has access to SVN_URL and SVN_REVISION.  My preferred language for my 
build system is Python, so I would probably shell out to an external Python 
script to parse the commit and contact Bugzilla for the summary.

I got some help from these:
https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin#Email-extplugin-PresendScript
https://www.cloudbees.com/jenkins/juc-2015/presentations/JUC-2015-USEast-Groovy-With-Jenkins-McCollum.pdf
https://wiki.jenkins-ci.org/display/JENKINS/Groovy+Postbuild+Plugin
http://www.groovy-lang.org/single-page-documentation.html
http://javadoc.jenkins-ci.org/

On Tuesday, October 13, 2015 at 11:07:55 AM UTC-4, slide wrote:
>
> Are you using email-ext or Mailer? If using email-ext, you could use a 
> SCRIPT token and have a groovy script that grabs anything you want from the 
> build.
>
> On Tue, Oct 13, 2015 at 7:55 AM Philippe Payant <philth...@gmail.com 
> <javascript:>> wrote:
>
>> Given that a Subversion comment  contains a Bugzilla bug number, for 
>> example:
>>
>> Fix Hoopla bug in the "easy" mode.  Bug 9413
>>
>> I would like the "build succesful" email to be something like:
>>
>> "MyProduct: build successful - bug 9413"
>>
>> For bonus points, I would actually like the subject to contain the 
>> Bugzilla summary of bug 9413:
>>
>> "MyProduct: build successful - bug 'Hoopla display is wrong in easy mode' 
>> "
>>
>>
>> -- Philippe
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Jenkins Users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to jenkinsci-use...@googlegroups.com <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/jenkinsci-users/6aad9b4a-de29-4d0a-9879-6136dd055302%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/jenkinsci-users/6aad9b4a-de29-4d0a-9879-6136dd055302%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/c62636ec-0d9d-4b65-9bf5-42291eb251cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to