Skip to content

[JENKINS-21311] Queue item cancellation via REST api works but returns a 404 #15277

Closed

Description

@jenkins-infra-bot

When I call http:///queue/cancelItem?id= it does cancel the item but it returns a 404. It must return a 200 instead.


Originally reported by barthelemy, imported from: Queue item cancellation via REST api works but returns a 404
  • assignee: pierrebtz
  • status: Resolved
  • priority: Minor
  • component(s): core
  • label(s): newbie-friendly, queue, rest, stapler
  • resolution: Fixed
  • resolved: 2020-03-08T22:18:29+00:00
  • votes: 3
  • watchers: 8
  • imported: 2025-11-24
Raw content of original issue

When I call http://<Jenkins_URL>/queue/cancelItem?id=<queueItem> it does cancel the item but it returns a 404. It must return a 200 instead.

  • environment: jenkins 1.546

Activity

  1. jenkins-infra-bot commented on Jan 9, 2014

    @jenkins-infra-bot
    Author
    • Remote link associated with this issue:

  2. jenkins-infra-bot commented on Jan 9, 2014

    @jenkins-infra-bot
    Author
    barthelemy:

    Probably related to JENKINS-16333

  3. jenkins-infra-bot commented on Oct 7, 2014

    @jenkins-infra-bot
    Author
    danielbeck:
    • Original comment link
    • Raw content of original comment:

      Is this still an issue in recent Jenkins versions? The Queue.doCancelItem code looks reasonable.

      Where is /queue/cancelItem documented as being part of the REST API?

    Is this still an issue in recent Jenkins versions? The Queue.doCancelItem code looks reasonable.

    Where is /queue/cancelItem documented as being part of the REST API?

  4. jenkins-infra-bot commented on Oct 7, 2014

    @jenkins-infra-bot
    Author
    jglick:
    • Original comment link
    • Raw content of original comment:

      Is this reproducible? doCancelItem unconditionally returns a redirect response. It should never be a 404, even if the queue item does not exist.

    Is this reproducible? doCancelItem unconditionally returns a redirect response. It should never be a 404, even if the queue item does not exist.

  5. jenkins-infra-bot commented on Oct 9, 2014

    @jenkins-infra-bot
    Author
    barthelemy:

    I have just tried again and could reproduce it with Jenkins 1.579.

    I did https://xxx.yyy.ch/jenkins/view/job//buildWithParameters?module=xyz
    And got a 201 with a location in the header : Location: https://xxx.yyy.ch/jenkins/queue/item/1137/

    I then I did : https://xxx.yyy.ch/jenkins/queue/cancelItem?id=1137
    And got the following header :
    Status Code: 404 Not Found
    Cache-Control: no-cache
    Connection: close
    Content-Length: 952
    Content-Type: text/html;charset=utf-8
    Date: Thu, 09 Oct 2014 11:45:15 GMT
    Expires: Thu, 01 Jan 1970 01:00:00 CET
    Pragma: No-cache

    Yet, the queue item was cancelled !

  6. jenkins-infra-bot commented on Oct 9, 2014

    @jenkins-infra-bot
    Author
    danielbeck:
    • Original comment link
    • Raw content of original comment:

      It makes sense to me now.

      It redirects to the referer URL, which, if that's not set, defaults to '.', or /queue/ (which isn't mean to be used interactively, so there's nothing there – 404).

      This is why I was asking where /queue/cancelItem was advertised as being part of the Jenkins API – it's not documented in /queue/api. If it's advertised nowhere, and you're just using it because it exists, then there's no reasonable expectation of URLs used by the Jenkins UI to also work outside that context.

    It makes sense to me now.

    It redirects to the referer URL, which, if that's not set, defaults to '.', or /queue/ (which isn't mean to be used interactively, so there's nothing there – 404).

    This is why I was asking where /queue/cancelItem was advertised as being part of the Jenkins API – it's not documented in /queue/api. If it's advertised nowhere, and you're just using it because it exists, then there's no reasonable expectation of URLs used by the Jenkins UI to also work outside that context.

  7. jenkins-infra-bot commented on Oct 9, 2014

    @jenkins-infra-bot
    Author
    barthelemy:

    Ok, fair enough.

    For information I got the information about it in these two places :
    http://stackoverflow.com/questions/21021905/how-to-stop-a-build-in-jenkins-via-the-rest-api
    https://groups.google.com/forum/#!topic/jenkinsci-users/aN_WFvgTz2Y

    Is there a more standard way of cancelling a queue item ?

  8. jenkins-infra-bot commented on Oct 9, 2014

    @jenkins-infra-bot
    Author
    barthelemy:
    • Original comment link
    • Raw content of original comment:

      Actually the second link points to a post from you

    Actually the second link points to a post from you

  9. jenkins-infra-bot commented on Oct 9, 2014

    @jenkins-infra-bot
    Author
    jglick:
    • Original comment link
    • Raw content of original comment:

      There are lots of API endpoints which are not documented, mainly because the creator did not document them. (In this case I am at fault, though I doubt the endpoint I was replacing was documented either.)

      So this is simply a bug. Using HttpResponses.forwardToPreviousPage() is commonplace in @RequirePOST endpoints that are not expected to display anything special where the UI invoker is just something that sends a POST via a form and does not want the rendered page to change. One easy fix would be to make this method in Stapler check whether there actually is a Referer, and if not, just delegate to ok() instead.

      The proper fix would probably be to think of this as a real API and return 204 No Content, optionally with some body or status message indicating whether anything was actually canceled. It is also necessary to ensure that whatever status code is chosen, stopButton.jelly (called from two places with cancelItem) will not try to reload the page. From the use of onclick="new Ajax.Request(this.href); return false" it looks like this would already be true regardless of the status code.

      And it looks like we need a Queue/_api.jelly listing the various operations. Currently this gives only generic information.

    There are lots of API endpoints which are not documented, mainly because the creator did not document them. (In this case I am at fault, though I doubt the endpoint I was replacing was documented either.)

    So this is simply a bug. Using HttpResponses.forwardToPreviousPage() is commonplace in @​RequirePOST endpoints that are not expected to display anything special where the UI invoker is just something that sends a POST via a form and does not want the rendered page to change. One easy fix would be to make this method in Stapler check whether there actually is a Referer, and if not, just delegate to ok() instead.

    The proper fix would probably be to think of this as a real API and return 204 No Content, optionally with some body or status message indicating whether anything was actually canceled. It is also necessary to ensure that whatever status code is chosen, stopButton.jelly (called from two places with cancelItem) will not try to reload the page. From the use of onclick="new Ajax.Request(this.href); return false" it looks like this would already be true regardless of the status code.

    And it looks like we need a Queue/_api.jelly listing the various operations. Currently this gives only generic information.

  10. jenkins-infra-bot commented on Oct 9, 2014

    @jenkins-infra-bot
    Author
    danielbeck:
    • Original comment link
    • Raw content of original comment:

      Alright, so it's actually a bug (although I maintain undocumented -> not really API).

      Reducing priority as it's essentially cosmetic and can be ignored; maybe just disable following the bogus redirect.

    Alright, so it's actually a bug (although I maintain undocumented -> not really API).

    Reducing priority as it's essentially cosmetic and can be ignored; maybe just disable following the bogus redirect.

  11. jenkins-infra-bot commented on Apr 19, 2018

    @jenkins-infra-bot
    Author
    deepchip:
    • Original comment link
    • Raw content of original comment:

      Running into this bug as I am adding the feature to cancel a queue item to the jenkins-rest java library. I use Jenkins 2.107.1.

    Running into this bug as I am adding the feature to cancel a queue item to the jenkins-rest java library. I use Jenkins 2.107.1.

  12. jenkins-infra-bot commented on Dec 15, 2019

    @jenkins-infra-bot
    Author
    pierrebtz:
    • Original comment link
    • Raw content of original comment:

      I also lost some time with this return code before seeing this issue, proposed some change to address this

    I also lost some time with this return code before seeing this issue, proposed some change to address this

  13. jenkins-infra-bot commented on Nov 24, 2025

    @jenkins-infra-bot
    Author

    [Original relates_to from Jira: JENKINS-16333]

  14. removed
    bugFor changelog: Minor bug. Will be listed after features
    on Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions