Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何访问';地点';从咖啡脚本中的HTTP响应?_Http_Jenkins_Http Headers_Coffeescript_Hubot - Fatal编程技术网

如何访问';地点';从咖啡脚本中的HTTP响应?

如何访问';地点';从咖啡脚本中的HTTP响应?,http,jenkins,http-headers,coffeescript,hubot,Http,Jenkins,Http Headers,Coffeescript,Hubot,我试图用Hubot将Jenkins和Slack结合起来。我在Hubot脚本中找到了脚本,它可以很好地完成我计划要做的事情。现在,我想在运行命令从Slack构建触发作业之后,获取该作业的构建编号。为了做到这一点,我想从http响应中获取“位置” 当我说@Hubot jenkins build jenkinsBuild=(msg,buildWithEmptyParameters)-> url=process.env.HUBOT\u JENKINS\u url job=querystring.esca

我试图用Hubot将Jenkins和Slack结合起来。我在Hubot脚本中找到了脚本,它可以很好地完成我计划要做的事情。现在,我想在运行命令从Slack构建触发作业之后,获取该作业的构建编号。为了做到这一点,我想从http响应中获取“位置”

当我说
@Hubot jenkins build

jenkinsBuild=(msg,buildWithEmptyParameters)->
url=process.env.HUBOT\u JENKINS\u url
job=querystring.escape msg.match[1]
params=msg.match[3]
命令=如果buildWithEmptyParameters,则为“buildWithParameters”,否则为“build”
路径=如果参数为“#{url}/job/#{job}/buildWithParameters?#{params}”否则“#{url}/job/#{job}/#{command}”
req=msg.http(路径)
如果process.env.HUBOT\u JENKINS\u AUTH
auth=新缓冲区(process.env.HUBOT\u JENKINS\u auth).toString('base64'))
req.headers授权:“基本#{auth}”
请求标题('Content-Length',0)
req.post()(错误、恢复、正文)->
如果出错
msg.reply“詹金斯说:{err}”

否则,如果200我最终用
res.headers[“location”]

完成了这项工作,这并不能回答这个问题。若要评论或要求作者澄清,请在其帖子下方留下评论。-OP回答了他/她自己的问题。我认为这提供了准确的信息;)
jenkinsBuild = (msg, buildWithEmptyParameters) ->
    url = process.env.HUBOT_JENKINS_URL
    job = querystring.escape msg.match[1]
    params = msg.match[3]
    command = if buildWithEmptyParameters then "buildWithParameters" else "build"
    path = if params then "#{url}/job/#{job}/buildWithParameters?#{params}" else "#{url}/job/#{job}/#{command}"

    req = msg.http(path)

    if process.env.HUBOT_JENKINS_AUTH
      auth = new Buffer(process.env.HUBOT_JENKINS_AUTH).toString('base64')
      req.headers Authorization: "Basic #{auth}"

    req.header('Content-Length', 0)
    req.post() (err, res, body) ->
        if err
          msg.reply "Jenkins says: #{err}"
        else if 200 <= res.statusCode < 400 # Or, not an error code.
          msg.reply "(#{res.statusCode}) Build started for #{job} #{url}/job/#{job}"
        else if 400 == res.statusCode
          jenkinsBuild(msg, true)
        else if 404 == res.statusCode
          msg.reply "Build not found, double check that it exists and is spelt correctly."
        else
          msg.reply "Jenkins says: Status #{res.statusCode} #{body}"