Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-39680

httpRequest method in Pipeline causes weird behavior

    XMLWordPrintable

    Details

    • Similar Issues:

      Description

      We're running into an issue with httpRequest in a Groovy script used on a mutlibranch pipeline job.

      I have code that looks something like this:

      /**** Jenkinsfile ****/
      // ...
      notify = load 'notify.groovy'
      // ...
      if (checkResults(...) > 0) {
          println 'Tests failed, stopping build'
          return 1
      }
      
      int checkResults(...) {
          // ...
          notify.buildFailed(...)
      
          return failedTestCount
      }
      
      /**** notify.groovy ****/
      
      void buildFailed(...) {
        // ...
        sendMessage(...)
      }
      
      void sendMessage(...) {
         // ...
        def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON',
          httpMode: 'POST', requestBody: body, consoleLogResponseBody: true,
          url: 'https://example.net/hooks/4ezwZwLYbmYwJmD6MXN6yH3YNdd/C6m5uKJstArcKQyxfBYb5nMW7PkPSriACsXg9w',
          validResponseContent: '"success":true'
      
        println "Sent a notification, got a $response.status response"
      }
      

      Expected Results

      When this code runs, I expect for the httpRequest to return the response, the code to get printed out from my println, then checkResults to return the number of failed tests it detected (code not shown). However, that's not what happens.

      Actual Results

      Instead, sendMessage immediately return without executing my println, and most oddly of all, checkResults ends up returning the HTTP Response from httpRequest! How is this even possible?

      The symptom, other than my println doing nothing, is that the > 0 comparison in the Jenkinsfile doesn't work and this exception is thrown:

      groovy.lang.GroovyRuntimeException: Cannot compare jenkins.plugins.http_request.ResponseContentSupplier with value 'Status: 200, Response: {"success":true}' and java.lang.Integer with value '0'
      

      It's possible that I'm doing something wrong here, but this seems very much like a bug. It's hard for me to imagine what I could do wrong that would cause the stack to get blown apart in such a way.

        Attachments

          Activity

          tyrelh Tyrel Haveman created issue -
          tyrelh Tyrel Haveman made changes -
          Field Original Value New Value
          Description We're running into an issue with {{httpRequest}} in a Groovy script used on a mutlibranch pipeline job.

          I have code that looks something like this:

          {code:java}
          /**** Jenkinsfile ****/
          // ...
          notify = load 'notify.groovy'
          // ...
          if (checkResults(...) > 0) {
              println 'Tests failed, stopping build'
              return 1
          }

          int checkResults(...) {
              // ...
              notify.buildFailed(...)

              return failedTestCount
          }

          /**** notify.groovy ****/

          void buildFailed(...) {
            // ...
            sendMessage(...)
          }

          void sendMessage(...) {
             // ...
            def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON',
              httpMode: 'POST', requestBody: body, consoleLogResponseBody: true,
              url: 'https://example.net/hooks/4ezwZwLYbmYwJmD6MXN6yH3YNdd/C6m5uKJstArcKQyxfBYb5nMW7PkPSriACsXg9w',
              validResponseContent: '"success":true'

            println "Sent a notification, got a $response.status response"
          }
          {code}

          h2. Expected Results
          When this code runs, I expect for the {{httpRequest}} to return the response, the code to get printed out from my {{println}}, then {{checkResults}} to return the number of failed tests it detected (code not shown). However, that's not what happens.

          h2. Actual Results
          Instead, {{sendMessage immediately return without executing my {{println}}, and most oddly of all, {{checkResults}} ends up returning the HTTP Response from {{httpRequest}}! How is this even possible?

          The symptom, other than my {{println}} doing nothing, is that the {{> 0}} comparison in the {{Jenkinsfile}} doesn't work and this exception is thrown:
          {noformat}
          groovy.lang.GroovyRuntimeException: Cannot compare jenkins.plugins.http_request.ResponseContentSupplier with value 'Status: 200, Response: {"success":true}' and java.lang.Integer with value '0'
          {noformat}

          It's possible that I'm doing something wrong here, but this seems very much like a bug. It's hard for me to imagine what I could do wrong that would cause the stack to get blown apart in such a way.
          We're running into an issue with {{httpRequest}} in a Groovy script used on a mutlibranch pipeline job.

          I have code that looks something like this:

          {code:java}
          /**** Jenkinsfile ****/
          // ...
          notify = load 'notify.groovy'
          // ...
          if (checkResults(...) > 0) {
              println 'Tests failed, stopping build'
              return 1
          }

          int checkResults(...) {
              // ...
              notify.buildFailed(...)

              return failedTestCount
          }

          /**** notify.groovy ****/

          void buildFailed(...) {
            // ...
            sendMessage(...)
          }

          void sendMessage(...) {
             // ...
            def response = httpRequest acceptType: 'APPLICATION_JSON', contentType: 'APPLICATION_JSON',
              httpMode: 'POST', requestBody: body, consoleLogResponseBody: true,
              url: 'https://example.net/hooks/4ezwZwLYbmYwJmD6MXN6yH3YNdd/C6m5uKJstArcKQyxfBYb5nMW7PkPSriACsXg9w',
              validResponseContent: '"success":true'

            println "Sent a notification, got a $response.status response"
          }
          {code}

          h2. Expected Results
          When this code runs, I expect for the {{httpRequest}} to return the response, the code to get printed out from my {{println}}, then {{checkResults}} to return the number of failed tests it detected (code not shown). However, that's not what happens.

          h2. Actual Results
          Instead, {{sendMessage}} immediately return without executing my {{println}}, and most oddly of all, {{checkResults}} ends up returning the HTTP Response from {{httpRequest}}! How is this even possible?

          The symptom, other than my {{println}} doing nothing, is that the {{> 0}} comparison in the {{Jenkinsfile}} doesn't work and this exception is thrown:
          {noformat}
          groovy.lang.GroovyRuntimeException: Cannot compare jenkins.plugins.http_request.ResponseContentSupplier with value 'Status: 200, Response: {"success":true}' and java.lang.Integer with value '0'
          {noformat}

          It's possible that I'm doing something wrong here, but this seems very much like a bug. It's hard for me to imagine what I could do wrong that would cause the stack to get blown apart in such a way.
          janario Janario Oliveira made changes -
          Status Open [ 1 ] In Progress [ 3 ]
          janario Janario Oliveira made changes -
          Status In Progress [ 3 ] Open [ 1 ]
          janario Janario Oliveira made changes -
          Resolution Cannot Reproduce [ 5 ]
          Status Open [ 1 ] Resolved [ 5 ]
          janario Janario Oliveira made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            Assignee:
            janario Janario Oliveira
            Reporter:
            tyrelh Tyrel Haveman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: