Querying the database to check whether the plan branches are set to clean up automatically or not

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

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

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!

Summary

When using plan branches, it's possible to configure whether they will be automatically cleaned up or not. The clean-up settings are set under the main plan branch configuration >> "Branches" tab >> "Delete plan branch" section, and they default to 7 days after deletion and 10 days of inactivity. For each plan branch, under the branch configuration >> "Branch details" tab, you can use the "Clean up plan branch automatically" checkbox to determine if that branch will or will not be cleaned up automatically. If the "Clean up plan branch automatically" checkbox is marked, the branch inherits the global plan values defined in the main plan and can eventually be deleted automatically by Bamboo; if unmarked, the branch will not be deleted automatically.

This article covers a SQL query to easily identify which plan branches have the "Clean up plan branch automatically" box checked and which do not.

You can learn more about plan branches here.

Environment

This was tested on Microsoft SQL Server 2019

Solution

SQL Query (MS SQL Server 2019)
SELECT
       (
           SELECT B1.TITLE
           FROM BUILD B1
           WHERE B1.BUILD_ID = B.MASTER_ID
       ) AS PLAN_NAME,
       B.TITLE AS PLAN_BRANCH_NAME,
       B.FULL_KEY AS PLAN_BRANCH_KEY,
       CASE
            WHEN BD.XML_DEFINITION_DATA LIKE ('%<cleanup>%<disabled>false</disabled>%</cleanup>%')
                THEN 'CHECKED'
            WHEN BD.XML_DEFINITION_DATA LIKE ('%<cleanup>%<disabled>true</disabled>%</cleanup>%')
                THEN 'UNCHECKED'
            ELSE ''
            END AS CLEANUP_BRANCH_CHECKED,
       CONCAT('<BAMBOO_URL>/branch/admin/config/editChainBranchDetails.action?buildKey=',B.FULL_KEY) AS URL
FROM BUILD_DEFINITION BD
JOIN BUILD B on BD.BUILD_ID = B.BUILD_ID
WHERE B.BUILD_TYPE = 'CHAIN_BRANCH'
ORDER BY PLAN_BRANCH_KEY

Please replace <BAMBOO_URL> with your Bamboo instance URL to get the URL column populated correctly.

If you use a different database management system, you might want to translate the query above into your DBMS's syntax.

Last modified on Feb 8, 2022

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.