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:
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: