jenkinsci / hipchat-plugin

HipChat notification plugin for Jenkins
https://plugins.jenkins.io/hipchat/
54 stars 85 forks source link

Notifications are randomly sent to hipchat #105

Closed TomGudman closed 7 years ago

TomGudman commented 7 years ago

Hi,

Context

Description

Hipchat messages are not sent (or plugin is not executed at all...) Statistically, it seems 'build failed" notifications go through 90% of the time while 'build success' notifications only reach hipchat 5% of the time. It is really an odd behaviour; it is random. It seems to only affect new projects but I am not 100% sure about that either.

Setup

Consequences

Config.xml

 <publishers>
    <htmlpublisher.HtmlPublisher plugin="htmlpublisher@1.12">
      <reportTargets>
        <htmlpublisher.HtmlPublisherTarget>
          <reportName>ScalaTest Report</reportName>
          <reportDir>target/htmldir</reportDir>
          <reportFiles>index.html</reportFiles>
          <alwaysLinkToLastBuild>false</alwaysLinkToLastBuild>
          <keepAll>false</keepAll>
          <allowMissing>true</allowMissing>
        </htmlpublisher.HtmlPublisherTarget>
        <htmlpublisher.HtmlPublisherTarget>
          <reportName>Coverage Report</reportName>
          <reportDir>target/scala-2.11/scoverage-report</reportDir>
          <reportFiles>index.html</reportFiles>
          <alwaysLinkToLastBuild>false</alwaysLinkToLastBuild>
          <keepAll>false</keepAll>
          <allowMissing>true</allowMissing>
        </htmlpublisher.HtmlPublisherTarget>
      </reportTargets>
    </htmlpublisher.HtmlPublisher>
    <hudson.tasks.junit.JUnitResultArchiver plugin="junit@1.20">
      <testResults>target/report/*.xml</testResults>
      <keepLongStdio>false</keepLongStdio>
      <healthScaleFactor>1.0</healthScaleFactor>
      <allowEmptyResults>true</allowEmptyResults>
    </hudson.tasks.junit.JUnitResultArchiver>
    <jenkins.plugins.hipchat.HipChatNotifier plugin="hipchat@2.1.1">
      <credentialId>HipChat-API-Token</credentialId>
      <room>Jenkoins</room>
      <notifications>
        <jenkins.plugins.hipchat.model.NotificationConfig>
          <notifyEnabled>true</notifyEnabled>
          <textFormat>false</textFormat>
          <notificationType>SUCCESS</notificationType>
          <color>GREEN</color>
          <messageTemplate></messageTemplate>
        </jenkins.plugins.hipchat.model.NotificationConfig>
        <jenkins.plugins.hipchat.model.NotificationConfig>
          <notifyEnabled>true</notifyEnabled>
          <textFormat>false</textFormat>
          <notificationType>FAILURE</notificationType>
          <color>RED</color>
          <messageTemplate></messageTemplate>
        </jenkins.plugins.hipchat.model.NotificationConfig>
      </notifications>
      <startJobMessage></startJobMessage>
      <completeJobMessage>$JOB_NAME - v$PROJECT_VERSION - #${BUILD_NUMBER} ${GIT_BRANCH}-${GIT_REVISION,length=8} - $STATUS after $BUILD_DURATION (&lt;a href=&quot;$BUILD_URL&quot;&gt;View build&lt;/a&gt;)</completeJobMessage>
    </jenkins.plugins.hipchat.HipChatNotifier>
  </publishers>

Once the completeJobMessage parameter is removed the behaviour remains the same except that sometimes (2 out of 3 tests) when I changed the hipchat config it seems that 'build successful' notification went through. Could be just luck but it seemed related. Spent 2h+ trying to understand the issue; it is hard to objective anymore.

Logs

Possible cause

References

aldaris commented 7 years ago

Build success notifications are only sent when the build result is success and the previous build result was also success. If the previous build result was something else than success, the notification type will be "back to normal" instead.

TomGudman commented 7 years ago

What about the first build? It did not send any success notification for the first time we built it (e.g: Job #1 is successful)

aldaris commented 7 years ago

Since https://github.com/jenkinsci/hipchat-plugin/blob/master/src/main/java/jenkins/plugins/hipchat/model/NotificationType.java#L136 doesn't check if previousResult was null, I guess it would be considered back to normal. That looks like a bug.

TomGudman commented 7 years ago

Ok cool. We are happy to test when you have the time to release a new version

Thank you for the explanation about 'Back to normal', we never used it and never understood its purpose and never realised its consequence until now. I will have to update all our jobs to support that.

TomGudman commented 7 years ago

FYI, since I have 'back to normal', the first build now sends a notification with a message 'Back to normal'. As you said it should technically be a 'build success' message instead.