Search code examples
hudsonjenkinshudson-plugins

How to include pom version number into Jenkins e-mail notification?


How to include pom version number into Jenkins e-mail notification?

This is to notify test team about a sucessful build and the build version. For now, we can only send a generic e-mail without any useful content in it.

I have tried the following but none of those sucess.

  • grep and export in a post build step but I can't pass that into the e-mail notification plugin
  • (.*) annotation but it dosen't work for the plugin.

Anyone have any idea?


Solution

  • You may use Extended Email Notification plugin that can parse your build log using regular expressions.

    When you install the plugin you first configure its default behavior on the main Jenkins configuration page. Then you customize it per job: go to Post-Build Actions and check 'Editable Email Notification' box. Use 'Content Token Reference' help button to get the tokens you may use. Among them will be BUILD_LOG_REGEX token with the explanation on its usage.

    So what you may do is to output your POM via the build log in some easily parseable form and then parse it out using BUILD_LOG_REGEX into your e-mail.

    Here's an actual test build (for Windows) that echoes boo_$BUILD_ID_foo line to the output, the plugin parses out that line and sends an email that looks like this:

    Here we go, Joe:
    boo_2012-01-30_23-04-29_foo
    

    config.xml for the job:

    <?xml version='1.0' encoding='UTF-8'?>
    <project>
      <actions/>
      <description></description>
      <keepDependencies>false</keepDependencies>
      <properties/>
      <scm class="hudson.scm.NullSCM"/>
      <canRoam>true</canRoam>
      <disabled>false</disabled>
      <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding>
      <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding>
      <triggers class="vector"/>
      <concurrentBuild>false</concurrentBuild>
      <builders>
        <hudson.tasks.BatchFile>
          <command>echo boo_%BUILD_ID%_foo
    </command>
        </hudson.tasks.BatchFile>
      </builders>
      <publishers>
        <hudson.plugins.emailext.ExtendedEmailPublisher>
          <recipientList>youemail@company.com</recipientList>
          <configuredTriggers>
            <hudson.plugins.emailext.plugins.trigger.FailureTrigger>
              <email>
                <recipientList></recipientList>
                <subject>$PROJECT_DEFAULT_SUBJECT</subject>
                <body>$PROJECT_DEFAULT_CONTENT</body>
                <sendToDevelopers>false</sendToDevelopers>
                <includeCulprits>false</includeCulprits>
                <sendToRecipientList>true</sendToRecipientList>
              </email>
            </hudson.plugins.emailext.plugins.trigger.FailureTrigger>
            <hudson.plugins.emailext.plugins.trigger.SuccessTrigger>
              <email>
                <recipientList></recipientList>
                <subject>$PROJECT_DEFAULT_SUBJECT</subject>
                <body>$PROJECT_DEFAULT_CONTENT</body>
                <sendToDevelopers>false</sendToDevelopers>
                <includeCulprits>false</includeCulprits>
                <sendToRecipientList>true</sendToRecipientList>
              </email>
            </hudson.plugins.emailext.plugins.trigger.SuccessTrigger>
          </configuredTriggers>
          <contentType>text/plain</contentType>
          <defaultSubject>$DEFAULT_SUBJECT</defaultSubject>
          <defaultContent>Here we go, Joe:
    ${BUILD_LOG_REGEX, regex=&quot;^boo.*?foo.*?$&quot;,showTruncatedLines=false}
    
    </defaultContent>
        </hudson.plugins.emailext.ExtendedEmailPublisher>
      </publishers>
      <buildWrappers/>
    </project>