会社でHubot入れてみた

前提条件

  • Ubuntu 14.04LTSにインストール
    • AdapterはIRC
    • 実はUbuntu 12.04LTSに入れようとしたけどhubot-ircの依存関係でエラー(irc-colors)が解決できず、断念した。

準備

  • 例によってProxyがあるので簡単に入れさせてくれません。
    • npm, git, github, yeomanとハマりどころ満載でした。
$ export http_proxy=http://proxy.example.com:8080
$ export HTTP_PROXY=http://proxy.example.com:8080
$ export https_proxy=http://proxy.example.com:8080
$ export HTTPS_PROXY=http://proxy.example.com:8080
$ npm config set proxy http://proxy.example.com:8080
$ npm config set https-proxy http://proxy.example.com:8080
$ npm -g config set registry http://registry.npmjs.org/
$ git config --global http.proxy=http://proxy.example.com:8080
$ git config --global https.proxy=http://proxy.example.com:8080
$ git config --global url.https://github.com/.insteadOf git://github.com/

インストール

  • node.jsをインストール
$ sudo aptitude install nodejs npm
  • npmでは、Globalでhubot, hubot-irc, coffee-scriptをインストール
    • hubotの初期化がyeoman出ないと出来ないようになったので、yo, generator-hubotも入れた
$ sudo npm install -g hubot hubot-irc coffee-script

Bot初期化

  • hubotスクリプト叩くといきなり/usr/bin/env: node: No such file or directoryというエラーが出るので調べたらCoffeeScriptの中で#!/usr/bin/env nodeってかいてあるじゃないですか。びみょー。。。
$ which nodejs
/usr/bin/nodejs
$ sudo ln -s /usr/bin/nodejs /usr/local/bin/node
  • 試しにfoobotというbotをyeomanで作成
    • 前述のProxy設定がちゃんとできてないとここでこけまくる。。。
yo hubot --owner=username@example.com --name=foobot --description="Foo Bot" --adapter=irc

Bot設定

  • Script追加
    • foobot配下のhubot-scripts.jsonに以下を追加。
["jenkins.coffee", "jenkins-notifier.coffee", "redmine.coffee"]
  • これでJenkinsのJobを呼んだり、Redmineのチケット表示したり出来るようになった。
    • scriptのヘッダ部分に使い方が書いてあるけど、例えばJenkinsでBuild with Prametersでやってる場合は以下のようにすれば呼べる。
> foobot jenkins build job_name, key=value&key2=value2
  • scriptは、foobot/node_modules/hubot-scripts/src/scriptsにたくさん入ってます。

おまけ

  • pug meやmap meなどの外を見るコマンドはプロキシ経由でRedmineなどの内部は直接見る必要がある。
    • foobot/node_modules/hubot/node_modules/scoped-http-client/src/index.jsを直接修正
      requestOptions = {
        //port: port,
        port: 3128,
        //host: this.options.hostname,
        host: '127.0.0.1',
        method: method,
        //path: this.fullPath(),
        path: 'http://' + this.options.hostname + this.fullPath(),
        headers: headers,
        agent: agent
      };
  • hostが127.0.0.1なのは、会社のProxyが内部へのアクセスをブロックするというえらい迷惑仕様なので、ローカルでSquidたてて内部OK、外部は会社のProxyへ流すというようにしてます。(;´д`)トホホ…