jenkins-hipchat-plugin icon indicating copy to clipboard operation
jenkins-hipchat-plugin copied to clipboard

Implement Mustache templates for messages

Open marcins opened this issue 12 years ago • 19 comments

A number of people in issue #12 have asked for the ability to customise the messages, such as adding build parameters etc. By using Mustache templates for build messages this can now be done.

This is quite a large change, and probably not as heavily tested as it should be. It probably needs some unit tests too. I am also not a Java developer, but "know" the language, so I might not have done everything optimally.

The README has been updates with information as to how the templates work, and the defaults should keep the messages the same as they were pre-Mustache.

This doesn't actually solve the original issue as it doesn't add the git branch name, and if the branch name isn't available through the accessible instance variables then it won't, I haven't checked.

It's probably a good start though!

marcins avatar Feb 09 '13 04:02 marcins

If anyone wants to try the plugin with Mustache notification templates I have a snapshot HPI up in Dropbox:

https://dl.dropbox.com/u/5336861/hipchat.hpi

YMMV, disclaimer, etc, etc :-)

Also check the updated README

marcins avatar Feb 09 '13 04:02 marcins

Any progress on accepting this? I would really like to add the description to my messages since i have "per PR" builds the number just becomes obsolete.

rdohms avatar Mar 05 '13 13:03 rdohms

@rdohms you can always run my snapshot HPI instead of the "official" one if you want the functionality now? Actually I should build a new one with the last 2 fixes in there, don't have time right now though.

marcins avatar Mar 06 '13 02:03 marcins

I am also interested in this.

Mange avatar Mar 28 '13 08:03 Mange

Nice work. Please add to master branch

phil-schneider avatar Mar 31 '13 08:03 phil-schneider

For all those that are interested, I've posted the latest snapshot HPI with these changes (based on at:

https://dl.dropbox.com/u/5336861/hipchat.hpi

I've been using this in production since I wrote it 2 months ago and haven't experienced any issues, although we do only have a small installation.

marcins avatar Mar 31 '13 09:03 marcins

I have another questions. Does your template replaces any parameter that are set by the build. Default parameter like $BUILD_ID and also custom parameter from a parameteriezed build?

phil-schneider avatar Mar 31 '13 17:03 phil-schneider

@phil-schneider - have a look at the README in my feature branch, it gives examples of how to access stuff about the build from the mustache templates:

marcins avatar Mar 31 '13 20:03 marcins

I installed this fork from the compiled https://dl.dropbox.com/u/5336861/hipchat.hpi link but for some reason I can't seem to customize the template. If I change either the global or project completion template I get an empty message (I just tried adding the word test into the template).

Apr 8, 2013 12:59:44 PM jenkins.plugins.hipchat.HipChatNotifier$HipChatJobProperty prebuild
INFO: Invoking Started...
Apr 8, 2013 12:59:44 PM jenkins.plugins.hipchat.ActiveNotifier getChanges
INFO: Empty change...
Apr 8, 2013 12:59:44 PM jenkins.plugins.hipchat.StandardHipChatService publish
INFO: Posting: Jenkins to 172833: Feature Test - #21: Started by user anonymous (<a href='/job/Feature%20Test/21/'>Open</a>) green
Apr 8, 2013 12:59:45 PM hudson.model.Run execute
INFO: Feature Test #21 main build action completed: SUCCESS
Apr 8, 2013 1:00:00 PM jenkins.plugins.hipchat.StandardHipChatService publish
INFO: Posting: Jenkins to 172833:  green

Notice the last line is missing the message.

iamamused avatar Apr 08 '13 17:04 iamamused

Interesting.. I'll look into it.

On Tue, Apr 9, 2013 at 3:14 AM, Jeffrey Sambells [email protected]:

I installed this fork from the compiled https://dl.dropbox.com/u/5336861/hipchat.hpi link but for some reason I can't seem to customize the template. If I change either the global or project completion template I get an empty message (I just tried adding the work test into the template.

Apr 8, 2013 12:59:44 PM jenkins.plugins.hipchat.HipChatNotifier$HipChatJobProperty prebuild INFO: Invoking Started... Apr 8, 2013 12:59:44 PM jenkins.plugins.hipchat.ActiveNotifier getChanges INFO: Empty change... Apr 8, 2013 12:59:44 PM jenkins.plugins.hipchat.StandardHipChatService publish INFO: Posting: Jenkins to 172833: Feature Test - #21: Started by user anonymous (Open) green Apr 8, 2013 12:59:45 PM hudson.model.Run execute INFO: Feature Test #21 main build action completed: SUCCESS Apr 8, 2013 1:00:00 PM jenkins.plugins.hipchat.StandardHipChatService publish INFO: Posting: Jenkins to 172833: green

Notice the last line is messing the message.

— Reply to this email directly or view it on GitHubhttps://github.com/jlewallen/jenkins-hipchat-plugin/pull/32#issuecomment-16064297 .

M.

marcins avatar Apr 08 '13 21:04 marcins

Actually it only seem sto be blank if I modify the project specific template. If I modify the global one it seems to ignore my settings and uses the default one.

iamamused avatar Apr 09 '13 01:04 iamamused

Also noticed that the global Build Server Url isn't applied in the Open link (everything lis linking as if it's a local file. It's like it's not reading my configuration. I'm running the latest version of Jenkins.

iamamused avatar Apr 09 '13 01:04 iamamused

From all those reports it looks like there's just an issue with applying the global config then? Although I'm pretty sure my production install is only using global config and it is working.

Will try and reproduce when I have some time (maybe add some unit tests!)

On Tue, Apr 9, 2013 at 11:13 AM, Jeffrey Sambells [email protected]:

Also noticed that the global Build Server Url isn't applied in the Open link (everything lis linking as if it's a local file. It's like it's not reading my configuration. I'm running the latest version of Jenkins.

— Reply to this email directly or view it on GitHubhttps://github.com/jlewallen/jenkins-hipchat-plugin/pull/32#issuecomment-16088805 .

M.

marcins avatar Apr 09 '13 01:04 marcins

Ya, possibly. Playing with it some more it seems editing the global config doesn't actually update the configs in jobs/ until after I delete and then re-added the hipchat phase. That fixed the Build Server URL but the custom messages still didn't work.

iamamused avatar Apr 09 '13 01:04 iamamused

I think this was an issue I ran into with the plugin before I made my changes - the global config is only loaded once when the plugin is initialised (so either when you first add it, or when the server starts up), it's not reloaded when it's changed. Job config is reloaded everytime.

On Tue, Apr 9, 2013 at 11:45 AM, Jeffrey Sambells [email protected]:

Ya, possibly. Playing with it some more it seems editing the global config doesn't actually update the configs in jobs/ until after I delete and then re-added the hipchat phase. That fixed the Build Server URL but the custom messages still didn't work.

— Reply to this email directly or view it on GitHubhttps://github.com/jlewallen/jenkins-hipchat-plugin/pull/32#issuecomment-16089697 .

M.

marcins avatar Apr 09 '13 01:04 marcins

ok, still can't figure out why the templates don't work though. The global one is ignored and the local changes just cause it to be blank. Here's my test job config if you can shed any insight:

</project>SpeakFeels-Mac-mini:Feature Test jenkins$ cat config.xml 
<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description>This is just a test project to play with all the settings in Jenkins. Please ignore any output.</description>
  <keepDependencies>false</keepDependencies>
  <properties>
    <jenkins.plugins.hipchat.HipChatNotifier_-HipChatJobProperty plugin="[email protected]">
      <room></room>
      <startNotification>true</startNotification>
      <notifySuccess>true</notifySuccess>
      <notifyAborted>true</notifyAborted>
      <notifyNotBuilt>true</notifyNotBuilt>
      <notifyUnstable>true</notifyUnstable>
      <notifyFailure>true</notifyFailure>
      <messageTemplateStarted>This is a test template for start</messageTemplateStarted>
      <messageTemplateCompleted>This is a test template for complete</messageTemplateCompleted>
      <messageTemplateSuffix></messageTemplateSuffix>
    </jenkins.plugins.hipchat.HipChatNotifier_-HipChatJobProperty>
  </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.Shell>
      <command>env;</command>
    </hudson.tasks.Shell>
  </builders>
  <publishers>
    <com.zanox.hudson.plugins.FTPPublisher plugin="[email protected]">
      <siteName>example.com</siteName>
      <entries>
        <com.zanox.hudson.plugins.Entry>
          <filePath>$REMOTE_DIR/build</filePath>
          <sourceFile>upload/*/**</sourceFile>
        </com.zanox.hudson.plugins.Entry>
      </entries>
      <useTimestamps>false</useTimestamps>
      <flatten>true</flatten>
      <skip>false</skip>
    </com.zanox.hudson.plugins.FTPPublisher>
    <jenkins.plugins.hipchat.HipChatNotifier plugin="[email protected]">
      <authToken>...removed...</authToken>
      <buildServerUrl>http://example.com/</buildServerUrl>
      <room>172833</room>
      <sendAs>Jenkins</sendAs>
      <messageTemplateStarted>{{build.project.displayName}} - {{build.displayName}}: {{trigger}} {{{link}}} test</messageTemplateStarted>
      <messageTemplateCompleted>{{build.project.displayName}} - {{build.displayName}}: {{status}} after {{build.durationString}} test</messageTemplateCompleted>
      <messageTemplateSuffix></messageTemplateSuffix>
    </jenkins.plugins.hipchat.HipChatNotifier>
  </publishers>
  <buildWrappers>
    <EnvInjectBuildWrapper plugin="[email protected]">
      <info>
        <propertiesContent>REMOTE_DIR=feature-test</propertiesContent>
        <loadFilesFromMaster>false</loadFilesFromMaster>
      </info>
    </EnvInjectBuildWrapper>
  </buildWrappers>
</project>

iamamused avatar Apr 09 '13 01:04 iamamused

@marcins I just tested this. It seems that it works perfectly except for setting a custom template per project. When doing that (even the default one, or just plain text) it seems to not send the notification.

Using the custom suffix seems to work.

Also I would suggest adding some sort of logging so we can see the output in the build script (currently there is NO way to figure out why the messages aren't being sent if the template is wrong)

drubin avatar Jun 16 '13 07:06 drubin

There seem to be three (this one, #38, #42) pull requests all about customizing the sent message. This one seems most flexible and could probably cover the use cases of the other two, but I worry about it being able to cover the dead simple: "I just want to change the text string a little bit" case without someone having to read the Mustache docs. How do the other maintainers feel?

kellybyrd avatar Jul 12 '13 22:07 kellybyrd

I think this is the best solution, as the readme is quite clear on how to do it. It's the most flexible solution

leifcr avatar May 22 '14 09:05 leifcr