Thursday, November 10, 2011

Installing HipChat in Jenkins/Hudson..

1. git clone https://github.com/jlewallen/jenkins-hipchat-plugin

2. Compile and build (See http://hustoknow.blogspot.com/2010/09/installing-java-on-ubuntu-1004.html and http://hustoknow.blogspot.com/2011/04/hudson-becomes-jenkins-compling-plugins.html)

3. Copy the target/.hpi file that got generated into your hudson/plugins dir.

4. Restart Hudson.

5. Go into the Configure Hudson and provide the API key/conference room.

6. Make sure to enable HipChat notifications in each of your build projects!

FYI - this plug-in uses the HipChat API to publish information to the respective room that you deisgnate:

https://github.com/jlewallen/jenkins-hipchat-plugin/blob/master/src/main/java/jenkins/plugins/hipchat/StandardHipChatService.java

   public void publish(String message, String color) {
      for(String roomId : roomIds) {
         logger.info("Posting: " + from + " to " + roomId + ": " + message + " " + color);
         HttpClient client = new HttpClient();
         String url = "https://api.hipchat.com/v1/rooms/message?auth_token=" + token;
         PostMethod post = new PostMethod(url);
         try {
            post.addParameter("from", from);
            post.addParameter("room_id", roomId);
            post.addParameter("message", message);
            post.addParameter("color", color);
            client.executeMethod(post);
         }
         catch(HttpException e) {
            throw new RuntimeException("Error posting to HipChat", e);
         }
         catch(IOException e) {
            throw new RuntimeException("Error posting to HipChat", e);
         }
         finally {
            post.releaseConnection();
         }
      }
   }

   public void rooms() {
      HttpClient client = new HttpClient();
      String url = "https://api.hipchat.com/v1/rooms/list?format=json&auth_token=" + token;
      GetMethod get = new GetMethod(url);
      try {
         client.executeMethod(get);
         logger.info(get.getResponseBodyAsString());
      }
      catch(HttpException e) {
         throw new RuntimeException("Error posting to HipChat", e);
      }
      catch(IOException e) {
         throw new RuntimeException("Error posting to HipChat", e);
      }
      finally {
         get.releaseConnection();
      }
   }

}

1 comment:

  1. When will this plugin move to hipchat api v2?

    ReplyDelete