How to purge all the queued jobs in the Bamboo

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

The steps outlined on this article are provided AS-IS. This means we've had reports of them working for some customers — under certain circumstances — yet are not officially supported, nor can we guarantee they'll work for your specific scenario.

You may follow through and validate them on your own non-prod environments prior to production or fall back to supported alternatives if they don't work out.

We also invite you to reach out to our Community for matters that fall beyond Atlassian's scope of support!

The article outlines the process for purging all queued jobs in Bamboo. This procedure is particularly useful if a misconfiguration in plan triggers has caused numerous jobs to be queued up, thereby keeping the agents occupied.

Environment

  • The solution was tested on Bamboo 9.6.1, but it will be applicable to other supported versions as well.

  • Python 3.12.4

  • Bash 3.2.57(1)

Solution

This task can be accomplished using Bamboo APIs along with scripting.

Step 1: Fetch the list of builds scheduled for execution and waiting in the build queue using api-latest-queue-get

Step 2: Iterate through the list of builds fetched in the above step and stop the builds one by one using api-latest-queue-projectkey-buildkey-buildnumber-delete

Below are example Python and Shell scripts developed for this purpose. Depending on system capabilities and preferences, one of these scripts can be used to achieve the task.

Before executing the script, substitute the below placeholders with actual values:

  • <bamboo-base-url> - Bamboo Server Base URL

  • <admin_username> - Admin username

  • <admin_password> - Admin password

PYTHON SCRIPT:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 import requests import json headers = { "Accept": "application/json" } base_url = "<bamboo-base-url>" username = "<admin_username>" password = "<admin_password>"   response = requests.get(f"{base_url}/rest/api/latest/queue?expand=queuedBuilds", auth=(username, password),headers=headers) if response.status_code == 200: try: data = response.json() queued_builds = data['queuedBuilds']['queuedBuild'] for build in queued_builds: build_number = build['buildResultKey'] # Make a DELETE request based on the buildNumber delete_url = f'{base_url}/rest/api/latest/queue/{build_number}' response = requests.delete(delete_url,auth=(username, password)) if response.status_code == 204: print(f"Build {build_number} deleted successfully.") else: print(f"Failed to delete build {build_number}.") except ValueError: print("Response is not in JSON format.") else: print(f"Failed to fetch queued builds. Status code: {response.status_code}")

Sample output:

1 2 3 4 Build TP-TES0-JOB1-45 deleted successfully. Build TP-TES1-JOB1-45 deleted successfully. Build TP-TES2-JOB1-43 deleted successfully. Build TP-TES-JOB1-58 deleted successfully.

SHELL SCRIPT:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 base_url="<bamboo-base-url>" username="<admin_username>" password="<admin_password>" buildKeys=$(curl --user ${username}:${password} --request GET --url "${base_url}"'/rest/api/latest/queue?expand=queuedBuilds' --header 'Accept: application/json'|jq -c -r '.queuedBuilds.queuedBuild.[].buildResultKey') for buildKey in ${buildKeys[@]}; do response=$(curl --write-out %{http_code} --silent --output /dev/null --user ${username}:${password} --request DELETE --url "${base_url}"'/rest/api/latest/queue/'"${buildKey}") if [[ "$response" -eq 204 ]] ; then echo "Build '"${buildKey}"' deleted successfully" else echo "Build '"${buildKey}"' deletion failed" fi done

Sample output:

1 2 3 4 5 6 7 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1103 0 1103 0 0 19883 0 --:--:-- --:--:-- --:--:-- 20054 Build 'TP-TES0-JOB1-46' deleted successfully Build 'TP-TES-JOB1-59' deleted successfully Build 'TP-TES1-JOB1-46' deleted successfully Build 'TP-TES2-JOB1-44' deleted successfully
Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.