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

Starting a job using the API returns 302 instead of 201

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • core
    • Jenkins: 2.138.1
      OS: Ubuntu 16.04.5 LTS

      Any time a job is started using the `/build` or `/buildWithParameters` URL (either via the job's page itself or via an API call), it always returns a `HTTP 302` response that redirects to the job's page, instead of the correct HTTP 201.

      This behavior contradicts the API documentation itself, which states:

      To programmatically schedule a new build, post to this URL (/build). If the build has parameters, post to this URL (/buildWithParameters) and provide the parameters as form data. Either way, the successful queueing will result in 201 status code with Location HTTP header pointing the URL of the item in the queue.

          [JENKINS-53869] Starting a job using the API returns 302 instead of 201

          Esteban Marin added a comment -

          This seems to happen when building a "Pipeline" build. For normal builds, this does not occur.

          Esteban Marin added a comment - This seems to happen when building a "Pipeline" build. For normal builds, this does not occur.

          Marcos Rivas added a comment -

          I can confirm this is an issue, there is no possible way to obtain the build number of a pipeline job that has been launched by calling /build or /buildWithParameters endpoint

          Marcos Rivas added a comment - I can confirm this is an issue, there is no possible way to obtain the build number of a pipeline job that has been launched by calling /build or /buildWithParameters endpoint

          Hi mrbq/jnazander/macjohnny,

          Is there update on this issue?

          Regards,
          Ardhendu Singh

          Ardhendu Shekhar Singh added a comment - Hi mrbq / jnazander / macjohnny , Is there update on this issue? Regards, Ardhendu Singh

          also createItem api does this

          it also gives you a redirect so if i do a post like this:

           

          DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> :method: POST
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> :scheme: https
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> :authority: xxxx
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> :path: /createItem?name=sandbox_C253ZR_NONE&mode=copy&from=salesDemo_DEV
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> content-type: application/json
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> accept: application/json
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> jenkins-crumb: XXXX
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> user-agent: Apache-HttpAsyncClient/5.1.2 (Java/17.0.4)
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> authorization: XXXX

           

          then i don't get right away 200 back but a redirect to a pure UI page

          (and i did set that i only accept application/json (or xml which also doesn't matter)

           

          DEBUG org.apache.hc.client5.http.headers - c-0000000001 << :status: 302
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 << date: Wed, 05 Oct 2022 09:30:13 GMT
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 << x-content-type-options: nosniff
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 << location: https://XXXXXXX/job/sandbox_C253ZR_NONE/configure
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 << content-length: 0
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 << server: Jetty(10.0.11)
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 << strict-transport-security: max-age=31536000
          DEBUG org.apache.hc.client5.http.headers - c-0000000001 << set-cookie: INGRESSCOOKIE=XXXXX path=/; HttpOnly; Secure

           

          that really doesn't look ok, if i use REST and i set the right accept then it shouldn't redirect me to a UI page.

          This really looks like a createJob done through the ui

          Johan Compagner added a comment - also createItem api does this it also gives you a redirect so if i do a post like this:   DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> :method: POST DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> :scheme: https DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> :authority: xxxx DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> :path: /createItem?name=sandbox_C253ZR_NONE&mode=copy&from=salesDemo_DEV DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> content-type: application/json DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> accept: application/json DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> jenkins-crumb: XXXX DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> user-agent: Apache-HttpAsyncClient/5.1.2 (Java/17.0.4) DEBUG org.apache.hc.client5.http.headers - c-0000000001 >> authorization: XXXX   then i don't get right away 200 back but a redirect to a pure UI page (and i did set that i only accept application/json (or xml which also doesn't matter)   DEBUG org.apache.hc.client5.http.headers - c-0000000001 << :status: 302 DEBUG org.apache.hc.client5.http.headers - c-0000000001 << date: Wed, 05 Oct 2022 09:30:13 GMT DEBUG org.apache.hc.client5.http.headers - c-0000000001 << x-content-type-options: nosniff DEBUG org.apache.hc.client5.http.headers - c-0000000001 << location: https://XXXXXXX/job/sandbox_C253ZR_NONE/configure DEBUG org.apache.hc.client5.http.headers - c-0000000001 << content-length: 0 DEBUG org.apache.hc.client5.http.headers - c-0000000001 << server: Jetty(10.0.11) DEBUG org.apache.hc.client5.http.headers - c-0000000001 << strict-transport-security: max-age=31536000 DEBUG org.apache.hc.client5.http.headers - c-0000000001 << set-cookie: INGRESSCOOKIE=XXXXX path=/; HttpOnly; Secure   that really doesn't look ok, if i use REST and i set the right accept then it shouldn't redirect me to a UI page. This really looks like a createJob done through the ui

            Unassigned Unassigned
            jnazander Jevgeni Nazander
            Votes:
            5 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: