How to identify and remove outdated deployment projects and deployment environments in Bamboo Data Center

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!

Over time, Bamboo users may create many deployment projects and deployment environments. Some of these might become outdated or unused but still remain in Bamboo. Even if they're not in use, they can affect Bamboo's performance, as the system relies on these deployment projects and environments.

This article will guide you on how to identify outdated or unused deployment projects and environments in Bamboo by querying the Bamboo database. It also includes scripts for removing these obsolete items.

Environment

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

  • Tested on Postgres and MSSQL

Solution

Identify and remove Deployment Projects

The following SQL queries can be executed on the Bamboo database to retrieve all deployment projects along with their last release date, regardless of the environments within each project. Based on your business requirements, you can determine which deployment project is considered outdated by comparing it to a specific date.

Outdated Deployment Projects

1 2 3 4 5 6 7 8 9 10 11 SELECT dp.DEPLOYMENT_PROJECT_ID, dp.NAME AS deployment_project_name, Max(dr.QUEUED_DATE) AS last_queued_date FROM DEPLOYMENT_PROJECT dp INNER JOIN DEPLOYMENT_ENVIRONMENT de ON de.PACKAGE_DEFINITION_ID = dp.DEPLOYMENT_PROJECT_ID INNER JOIN DEPLOYMENT_RESULT dr ON de.ENVIRONMENT_ID = dr.ENVIRONMENT_ID GROUP BY dp.DEPLOYMENT_PROJECT_ID, dp.NAME ORDER BY last_queued_date;

Sample Output

1 2 3 4 5 6 7 8 deployment_project_id | deployment_project_name | last_queued_date -----------------------+--------------------------+------------------------- 13729840 | A_DEP_project 47 | 2024-09-07 21:42:27.445 13729819 | A_DEP_project 26 | 2024-09-07 21:42:57.843 13729836 | A_DEP_project 43 | 2024-09-07 21:43:42.085 13729835 | A_DEP_project 42 | 2024-09-07 21:44:24.502 13729829 | A_DEP_project 36 | 2024-09-07 21:44:31.054 (5 rows - Output records count may vary in your case)

The following SQL queries can be executed on the Bamboo database to retrieve all deployment projects that have no releases associated with any of their deployment environments.

Unused Deployment Projects

1 2 3 4 5 6 7 8 9 10 SELECT dp.DEPLOYMENT_PROJECT_ID, dp.NAME AS deployment_project_name FROM DEPLOYMENT_PROJECT dp INNER JOIN DEPLOYMENT_ENVIRONMENT de ON de.PACKAGE_DEFINITION_ID = dp.DEPLOYMENT_PROJECT_ID LEFT JOIN DEPLOYMENT_RESULT dr ON dr.ENVIRONMENT_ID = de.ENVIRONMENT_ID GROUP BY dp.DEPLOYMENT_PROJECT_ID, dp.NAME HAVING Count(dr.QUEUED_DATE) = 0;

Sample Output

1 2 3 4 5 6 7 8 deployment_project_id | deployment_project_name -----------------------+-------------------------- 950273 | Deployment project 47261 950274 | Deployment project 29259 950275 | Deployment project 99817 950276 | Deployment project 59091 950277 | Deployment project 73327 (5 rows - Output records count may vary in your case)

A deployment project list generated by the above query may not accurately reflect whether a project is unused. The absence of results could be due to previous deployments having failed (with those failures having expired) or it may simply indicate that no deployments have been made yet. Therefore, it is important to audit the list to accurately identify unused deployment projects.

Using the queries provided above, you can identify deployment projects that are no longer required. Follow the steps below to proceed with deleting these projects:

  • List down the DEPLOYMENT_PROJECT_IDs and save it in a text file as shown below:

deployment_project_ids.txt

1 2 3 4 5 950273 950274 13729840 13729819 13729829

  • After preparing the file, use the below shell script to for deleting the deployment projects from the Bamboo using the Delete Deployment Project Rest API. 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

    • <file_path> - File path where file deployment_project_ids.txt is located

delete_deployment_project_script.sh

1 2 3 4 5 6 7 8 9 10 11 12 13 BAMBOO_URL="<bamboo-base-url>" USERNAME="<admin_username>" PASSWORD="<admin_password>" for i in $(cat <file_path>/deployment_project_ids.txt); do echo "Deleting Deployment project $i" response=$(curl --write-out %{http_code} --silent --output /dev/null --user ${USERNAME}:${PASSWORD} --request DELETE --url ${BAMBOO_URL}/rest/api/latest/deploy/project/${i}) if [[ "$response" -eq 204 ]] ; then echo "Deployment project $i deleted successfully" else echo "Deployment project $i deletion failed" fi done

Identify and remove Deployment Environments

The following SQL queries can be executed on the Bamboo database to retrieve all deployment environments along with their last release date. Based on your business requirements, you can identify which deployment environments are considered outdated by comparing their last release date to a specific date.

Outdated Deployment Environments

1 2 3 4 5 6 7 8 9 10 11 12 13 SELECT dp.NAME AS deployment_project_name, de.NAME AS deployment_environment_name, de.ENVIRONMENT_ID AS DEPLOYMENT_ENVIRONMENT_ID,       Max(dr.QUEUED_DATE) AS last_queued_date FROM DEPLOYMENT_PROJECT dp INNER JOIN DEPLOYMENT_ENVIRONMENT de ON de.PACKAGE_DEFINITION_ID = dp.DEPLOYMENT_PROJECT_ID INNER JOIN DEPLOYMENT_RESULT dr ON de.ENVIRONMENT_ID = dr.ENVIRONMENT_ID GROUP BY dp.NAME, de.NAME, de.ENVIRONMENT_ID ORDER BY last_queued_date;

Sample Output

1 2 3 4 5 6 7 8 deployment_project_name | deployment_environment_name | deployment_environment_id | last_queued_date --------------------------+-----------------------------+---------------------------+------------------------- A_DEP_project 0 | A-Env165 | 13795494 | 2024-09-07 21:37:22.32 A_DEP_project 0 | A-Env198 | 13795527 | 2024-09-07 21:37:22.32 A_DEP_project 11 | A-Env16 | 13800845 | 2024-09-07 21:37:22.32 A_DEP_project 17 | A-Env22 | 13803851 | 2024-09-07 21:37:22.32 A_DEP_project 0 | A-Env231 | 13795560 | 2024-09-07 21:37:22.322 (5 rows - Output records count may vary in your case)

The following SQL queries can be executed on the Bamboo database to retrieve all deployment environments that have no associated releases.

Unused Deployment Environments

1 2 3 4 5 6 7 8 9 10 11 12 SELECT dp.NAME AS deployment_project_name, de.NAME AS deployment_environment_name, de.ENVIRONMENT_ID as DEPLOYMENT_ENVIRONMENT_ID FROM DEPLOYMENT_PROJECT dp INNER JOIN DEPLOYMENT_ENVIRONMENT de ON de.PACKAGE_DEFINITION_ID = dp.DEPLOYMENT_PROJECT_ID LEFT JOIN DEPLOYMENT_RESULT dr ON dr.ENVIRONMENT_ID = de.ENVIRONMENT_ID WHERE dr.QUEUED_DATE IS NULL GROUP BY dp.NAME, de.NAME, de.ENVIRONMENT_ID;

Sample Output

1 2 3 4 5 6 7 8 deployment_project_name | deployment_environment_name | deployment_environment_id --------------------------+-----------------------------+--------------------------- ABC_DEP_project 0 | A-Env0 | 14778369 ABC_DEP_project 0 | A-Env1 | 14778370 ABC_DEP_project 0 | A-Env2 | 14778371 ABC_DEP_project 0 | A-Env3 | 14778372 ABC_DEP_project 0 | A-Env4 | 14778373 (5 rows - Output records count may vary in your case)

A deployment environment list generated by the above query may not accurately reflect whether a environment is unused. The absence of results could be due to previous deployments having failed (with those failures having expired) or it may simply indicate that no deployments have been made yet. Therefore, it is important to audit the list to accurately identify unused deployment environments.

Using the queries provided above, you can identify deployment environments that are no longer required. Follow the steps below to proceed with deleting these environments:

  • List down the DEPLOYMENT_ENVIRONMENT_IDs and save it in a text file as shown below:

deployment_environment_ids.txt

1 2 3 4 5 14778372 14778369 13729840 14800845 13729829

Note

Currently, there is no REST API available for deleting deployment environments. Instead, the following script simulates user actions from the browser. A feature request BAM-25892 - Add REST API to delete the Deployment Environment is currently open to add this functionality via a REST API. Once the API is implemented, the script will be updated accordingly to utilize the new API for deleting deployment environments.

  • After preparing the file, use the below shell script to for deleting the deployment projects from the Bamboo. 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

    • <file_path> - File path where file deployment_environment_ids.txt is located

delete_deployment_project_script.sh

1 2 3 4 5 6 7 8 9 10 11 12 13 BAMBOO_URL="<bamboo-base-url>" USERNAME="<admin_username>" PASSWORD="<admin_password>" for i in $(cat <file_path>/deployment_environment_ids.txt); do echo "Deleting Deployment Environment $i" response=$(curl --write-out %{http_code} --silent --output /dev/null --url "${BAMBOO_URL}/deploy/deleteEnvironment.action?id=$i&confirm=true" -X POST -H "X-Atlassian-Token: no-check" --user ${USERNAME}:${PASSWORD}) if [[ "$response" -eq 302 ]] ; then echo "Deployment environment $i deleted successfully" else echo "Deployment environment $i deletion failed" fi done
Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.