 
     job = CONFIG[environment].job
     role = CONFIG[environment].role
-    paramName = CONFIG[environment].param ||= "BRANCH"
-    params = "#{paramName}=#{branch}"
+    paramKeys = CONFIG[environment].params ||= "BRANCH"
+    paramKeys = paramKeys.split(',')
 
     if not userHasRole(user, role)
        msg.send "Access denied."
        msg.send "You must have this role to use this command: #{role}"
        return
+
+    if paramKeys.length isnt paramValues.length
+      msg.send 'Invalid parameters.'
+      msg.send "Valid parameters are: #{(key for key of paramKeys)}"
+
+    count = paramKeys.length - 1
+    params = ''
+    for i in [0..count]
+      params += "#{paramKeys[i]}=#{paramValues[i]}"
+      if i isnt count
+        params += ','
 
     # monkeypatch the msg.match object
     msg.match[1] = job

# Author:
#   danriti

querystring = require 'querystring'

module.exports = (robot) ->

  if process.env.HUBOT_DEPLOY_CONFIG?
    CONFIG = JSON.parse process.env.HUBOT_DEPLOY_CONFIG
  else
    robot.logger.warning 'The HUBOT_DEPLOY_CONFIG environment variable is not set'
    CONFIG = {}

  userHasRole = (user, role) ->

#   Deploy wrapper script for Jenkins CI Hubot script
#
# Configuration:
#   HUBOT_JENKINS_DEPLOY_CONFIG - A JSON string that describes your deploy configuration.
#
# Commands:
#   hubot deploy <job> <params> - deploy the specified job with the specified param(s)
#   hubot build <job> <params> - build the specified job with the specified param(s)
#   hubot test <job> <params> - test the specified job with the specified param(s)
#
# Notes:
#   HUBOT_JENKINS_DEPLOY_CONFIG expects a JSON object structured like this:
#
#   { "foo": {
#       "job": "deploy-foo",
#       "params": "BRANCH,REGION"
#       "role": "deploy",
#     }
#   }
#
#   - "foo" (String) Human readable job you want to invoke.
#   - "job" (String) Name of the Jenkins job you want to invoke.
#   - "params" (String) Comma seperated string of all the parameter keys to be
#     passed to the Jenkins job.
#   - "role" (String) (Optional) Uses the [hubot-auth][1] module (requires
#     installation) for restricting access via user configurable roles.
#
