{"action":"opened","issue":{"url":"https://api.github.com/repos/github/hubot-scripts/issues/1631","labels_url":"https://api.github.com/repos/github/hubot-scripts/issues/1631/labels{/name}","comments_url":"https://api.github.com/repos/github/hubot-scripts/issues/1631/comments","events_url":"https://api.github.com/repos/github/hubot-scripts/issues/1631/events","html_url":"https://github.com/github/hubot-scripts/issues/1631","id":67019679,"number":1631,"title":"TeamCity Script Help","user":{"login":"alexcurtin","id":9538405,"avatar_url":"https://avatars.githubusercontent.com/u/9538405?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcurtin","html_url":"https://github.com/alexcurtin","followers_url":"https://api.github.com/users/alexcurtin/followers","following_url":"https://api.github.com/users/alexcurtin/following{/other_user}","gists_url":"https://api.github.com/users/alexcurtin/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcurtin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcurtin/subscriptions","organizations_url":"https://api.github.com/users/alexcurtin/orgs","repos_url":"https://api.github.com/users/alexcurtin/repos","events_url":"https://api.github.com/users/alexcurtin/events{/privacy}","received_events_url":"https://api.github.com/users/alexcurtin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-04-08T00:25:48Z","updated_at":"2015-04-08T00:25:48Z","closed_at":null,"body":"I am trying to make a TeamCity script that lets our developers more easily deploy a build than the existing teamcity.coffee script in the repo. I want a build ID # to be mapped to a easy project name, like \"web\" or \"database\". Below is the script so far, but no luck. I am getting [Wed Apr 08 2015 00:18:02 GMT+0000 (UTC)] ERROR TypeError: undefined is not a function at the @ sign.\r\n\r\n# Description:\r\n#    wrapper for TeamCity REST API for deployments\r\n#\r\n# Dependencies:\r\n#    \"underscore\": \"1.3.3\"\r\n#\r\n# Configuration:\r\n#    HUBOT_TEAMCITY_USERNAME = <user name>\r\n#    HUBOT_TEAMCITY_PASSWORD = <password>\r\n#    HUBOT_TEAMCITY_HOSTNAME = <host : port>\r\n#    HUBOT_TEAMCITY_SCHEME = <http || https> defaults to http if not set.\r\n#\r\n# Commands:\r\n#    hubot deploy <project> - Deploy project named <project>\r\n#    hubot deploy branch <project> - Deploy branch project named <project>\r\n#\r\n# Author:\r\n#    Kevin Van Heusen\r\n\r\nutil                    = require 'util'\r\n_                       = require 'underscore'\r\n\r\nconsole.log \"1\"\r\nmodule.exports = (robot) ->\r\n  username = process.env.HUBOT_TEAMCITY_USERNAME\r\n  password = process.env.HUBOT_TEAMCITY_PASSWORD\r\n  hostname = process.env.HUBOT_TEAMCITY_HOSTNAME\r\n  scheme = process.env.HUBOT_TEAMCITY_SCHEME || \"http\"\r\n  base_url = \"#{scheme}://#{hostname}\"\r\n  # trunk TC deploy projects - map of friendly alias to TC build ID\r\n  trunkProjectMap =\r\n      'cloud': 'bt88'\r\n      'db': 'bt89'\r\n      'database': 'bt89'\r\n  # branch TC deploy projects - map of friendly alias to TC build ID\r\n  branchProjectMap =\r\n      'cloud': 'branch1'\r\n      'db': 'branch2'\r\n      'database': 'branch2'\r\n  # Deploy the correct builds\r\n  deploy: (msg = {}, map = {}) ->\r\n      projectName = msg.match[1]\r\n      if projectName == \"all\"\r\n          for key, value of map\r\n              @add2Queue(msg, projectName, value)\r\n      else\r\n          for key, value of map\r\n              @add2Queue(msg, projectName, value) if key == projectName\r\n      return true\r\n\r\n  # Add to deploy queue\r\n  add2Queue: (msg, projectName, buildId) ->\r\n      url = \"#{base_url}/httpAuth/action.html?add2Queue=#{buildId}\"\r\n      headers = Authorization: \"Basic #{new Buffer(\"#{username}:#{password}\").toString(\"base64\")}\", Accept: \"application/json\"\r\n      msg.http(url)\r\n          .headers(headers)\r\n          .get() (err, res, body) ->\r\n              if res.statusCode == 200\r\n                  msg.send(\"Deploying #{projectName}\")\r\n              else\r\n                  msg.send(\"Fail! Something went wrong. Couldn't start the build for some reason. Build Id is #{buildId}\")\r\n      return true\r\n\r\n  # Deploy\r\n  robot.respond /deploy (.*)/i, (msg) ->\r\n    @deploy(msg, @trunkProjectMap)\r\n  robot.respond /deploy branch (.*)/i, (msg) ->\r\n    @deploy(msg, @branchProjectMap)"}}