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

Starting a job with params using REST Api doesn't return 201 http status code as stated in the documentation

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Critical
    • Resolution: Fixed
    • Component/s: core
    • Labels:
    • Environment:
      Linux
    • Similar Issues:

      Description

      This bug is related to the new enhancement that was added in v1.519 for better tracking a queued job.
      When starting the job with parameters I expect to get 201 status code, but instead I'm getting 302 code which redirects me to the "Location" header url.
      See attached screenshot from the request and the response (taken by Fiddler)

        Attachments

          Activity

          Hide
          scm_issue_link SCM/JIRA link daemon added a comment -

          Code changed in jenkins
          User: Craig Rodrigues
          Path:
          src/test/groovy/com/cloudbees/plugins/flow/ConcurrencyTest.groovy
          http://jenkins-ci.org/commit/build-flow-plugin/faeaa5cc2062f7c7b73073e201b12646e9538963
          Log:
          Delete test which no longer works in 1.521+ due to improved core behavior from JENKINS-18407

          Due to the improved core behavior, in JobInvocation.groovy's run()
          method, schedule2() no longer returns null when invoked from the test.

          Show
          scm_issue_link SCM/JIRA link daemon added a comment - Code changed in jenkins User: Craig Rodrigues Path: src/test/groovy/com/cloudbees/plugins/flow/ConcurrencyTest.groovy http://jenkins-ci.org/commit/build-flow-plugin/faeaa5cc2062f7c7b73073e201b12646e9538963 Log: Delete test which no longer works in 1.521+ due to improved core behavior from JENKINS-18407 Due to the improved core behavior, in JobInvocation.groovy's run() method, schedule2() no longer returns null when invoked from the test.
          Hide
          jnazander Jevgeni Nazander added a comment -

          It seems that this bug is still present (version 2.138.1) - every time when a build is triggered using `POST /job/[JOB_NAME]/build` (either normally or via Curl), jenkins ALWAYS returns 302 instead of 201. This makes it impossible to trigger builds via a webhook, because the HTTP client sees that the response code is not 2xx and starts retrying it.

          Show
          jnazander Jevgeni Nazander added a comment - It seems that this bug is still present (version 2.138.1) - every time when a build is triggered using `POST /job/ [JOB_NAME] /build` (either normally or via Curl), jenkins ALWAYS returns 302 instead of 201. This makes it impossible to trigger builds via a webhook, because the HTTP client sees that the response code is not 2xx and starts retrying it.
          Hide
          jglick Jesse Glick added a comment -

          Jevgeni Nazander no you are just using the wrong endpoint (build vs. buildWithParameters). Please use the users’ list for assistance. If you believe you have encountered a bug please file a fresh report with complete steps to reproduce from scratch, linking to existing issues as appropriate.

          Show
          jglick Jesse Glick added a comment - Jevgeni Nazander no you are just using the wrong endpoint ( build vs. buildWithParameters ). Please use the users’ list for assistance. If you believe you have encountered a bug please file a fresh report with complete steps to reproduce from scratch, linking to existing issues as appropriate.
          Hide
          jnazander Jevgeni Nazander added a comment -

          Jesse Glick But my job doesn't have parameters, and if I try calling the job using `/buildWithParameters`, it returns HTTP 500 – `IllegalStateException: This build is not parameterized!`

           

          In any case, Jenkins's API documentation says:

          `To programmatically schedule a new build, post to this URL (https://jenkins.***.net/job/accounts/build). If the build has parameters, post to this URL and provide the parameters as form data. Either way, the successful queueing will result in 201 status code`

          While in reality it returns 302. This looks like a bug to me, should I create a new ticket?

          Show
          jnazander Jevgeni Nazander added a comment - Jesse Glick But my job doesn't have parameters, and if I try calling the job using `/buildWithParameters`, it returns HTTP 500 – `IllegalStateException: This build is not parameterized!`   In any case, Jenkins's API documentation says: `To programmatically schedule a new build, post to this URL ( https://jenkins.***.net/job/accounts/build ). If the build has parameters, post to this URL and provide the parameters as form data. Either way, the successful queueing will result in 201 status code` While in reality it returns 302. This looks like a bug to me, should I create a new ticket?
          Hide
          jglick Jesse Glick added a comment -

          If your job has parameters, use buildWithParameters. If it does not, use build. Which is what the API documentation says. There is no bug I can see. Again please use the users’ list for assistance.

          Show
          jglick Jesse Glick added a comment - If your job has parameters, use buildWithParameters . If it does not, use build . Which is what the API documentation says. There is no bug I can see. Again please use the users’ list for assistance.

            People

            • Assignee:
              kohsuke Kohsuke Kawaguchi
              Reporter:
              amoss166 Amos Sonnenwirth
            • Votes:
              6 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: