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

httpRequest method in Pipeline causes weird behavior

      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.

          [JENKINS-39680] httpRequest method in Pipeline causes weird behavior

          Tyrel Haveman created issue -
          Tyrel Haveman made changes -
          Description Original: 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.
          New: 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 Oliveira made changes -
          Status Original: Open [ 1 ] New: In Progress [ 3 ]
          Janario Oliveira made changes -
          Status Original: In Progress [ 3 ] New: Open [ 1 ]
          Janario Oliveira made changes -
          Resolution New: Cannot Reproduce [ 5 ]
          Status Original: Open [ 1 ] New: Resolved [ 5 ]
          Janario Oliveira made changes -
          Status Original: Resolved [ 5 ] New: Closed [ 6 ]

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

              Created:
              Updated:
              Resolved: