Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

245
Vistas
Expected values not returned in coffee script

In:

jenkinsGetCSRFCrumb = (msg) ->
  url = process.env.HUBOT_JENKINS_URL
  path = "#{url}/crumbIssuer/api/json"
  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)
  crumb = {}
  req.get() (err, res, body) ->
    if err
      msg.send "Jenkins says getting crumb: #{err}"
    else
      response = ""
      try
        content = JSON.parse(body)
        crumb = content
        msg.send "Jenkins CSRF crumb response: #{JSON.stringify(content)}"
        msg.send "Jenkins CSRF crumb: #{crumb.crumb}"
      catch error 
        msg.send error 
   return crumb

and a calling function:

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)
    crumb = jenkinsGetCSRFCrumb(msg)
    req.header('Jenkins-Crumb', crumb.crumb)
    msg.reply "Got crumb: #{crumb.crumb}"
    msg.reply "Got crumb: #{JSON.stringify(crumb)}"
    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}"

the crumb return value does not seem to be returned to the calling function producing:

Got crumb: {}
Jenkins CSRF crumb response: {"_class":"hudson.security.csrf.DefaultCrumbIssuer","crumb":"4a70e657a96579abd72ae674fba0a16873b55cb7643cf5a5b54a1181c9296ffa","crumbRequestField":"Jenkins-Crumb"}
Jenkins CSRF crumb: 4a70e657a96579abd72ae674fba0a16873b55cb7643cf5a5b54a1181c9296ffa

Why is the returned value empty?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda