Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Mustache templates for messages #32

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

marcins
Copy link

@marcins marcins commented Feb 9, 2013

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!

Marcin Szczepanski and others added 16 commits February 8, 2013 20:08
Updated to use Jenkins 1.500 and added the Java implementation
of Mustache from https://github.com/spullara/mustache.java
The plugin will now use Mustache template from configuration when
creating HipChat notifications. This allows you to use any values
available in the build / project configuration, including your own
custom parameters.
When there is no config set there was an empty message being sent,
instead make sure the defaults are used.
MessageBuilder is no longer required since we now generate messages
using Mustache.
And some minor fixes to ensure there's no doubling up of "Started"
text.
Previous code was incorrectly getting message templates from
the global notifier instead of using the JobProperties object
Use a single "trigger" string that's the same as the non-Mustache
version's string instead of separate cause & changes strings which
could cause duplications.
@marcins
Copy link
Author

marcins commented Feb 9, 2013

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

Marcin Szczepanski added 2 commits February 9, 2013 15:20
If the build fails then the completion message may
contain HTML. This means the default message needs to
triple 'stache "status" so that the correct output is generated.
@rdohms
Copy link

rdohms commented Mar 5, 2013

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.

@marcins
Copy link
Author

marcins commented Mar 6, 2013

@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.

@Mange
Copy link

Mange commented Mar 28, 2013

I am also interested in this.

@phil-schneider
Copy link
Contributor

Nice work. Please add to master branch

Marcin Szczepanski added 2 commits March 31, 2013 20:32
Inefficient use of concatenated strings with String builder when creating the link to the build job.
Style fix to check for blank strings based on feedback.
@marcins
Copy link
Author

marcins commented Mar 31, 2013

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.

@phil-schneider
Copy link
Contributor

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?

@marcins
Copy link
Author

marcins commented Mar 31, 2013

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

@iamamused
Copy link

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.

@marcins
Copy link
Author

marcins commented Apr 8, 2013

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//pull/32#issuecomment-16064297
.

M.

@iamamused
Copy link

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
Copy link

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.

@marcins
Copy link
Author

marcins commented Apr 9, 2013

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//pull/32#issuecomment-16088805
.

M.

@iamamused
Copy link

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.

@marcins
Copy link
Author

marcins commented Apr 9, 2013

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//pull/32#issuecomment-16089697
.

M.

@iamamused
Copy link

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>

@drubin
Copy link

drubin commented Jun 16, 2013

@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)

@kellybyrd
Copy link
Collaborator

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?

@leifcr
Copy link

leifcr commented May 22, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants