How to locate Plans with disabled Plan Branch cleanup settings in Bamboo
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
Bamboo will not enable any Plan Branch cleanup policy by default, meaning that every Plan Branch that is created from a Repository Branch in Bamboo will not be cleaned unless instructed. This is to prevent Plan branches from being deleted without further notice. It is up to each Development Team and Bamboo Administrators to define a policy that would better fit into each company's rules and add custom "Delete plan branch" settings on a per-plan basis. It is also advisable to communicate this behaviour to all Development teams so they can work on adjusting their Plans and have a better Plan branch removal policy.
This is also documented on Bamboo Specs:
https://docs.atlassian.com/bamboo-specs-docs/8.2.1/specs.html?java#handling-deleted-branches
Don’t delete (Java Specs default) If a branch in the primary source repository is inactive, Bamboo does not automatically delete the corresponding plan branch.
Just like the UI settings, the default behaviour for Specs changes is to not set any immediate destructive setting, including Plan Branch expiry/deletion.
Environment
Bamboo 7, 8, 9
Solution
Bamboo will not provide you with a reporting interface where you can search for such settings. For that, we recommend you run some SQL statements to find the information you are looking for.
The SQL below will return every Plan that has a disabled Plan branch clean-up setting and their current settings.
The provided SQL instructions were tested only on PostgresSQL. You may have to adapt the queries for other databases.
Building SQL statements for reporting purposes is not part of the Atlassian Support scope and this work is provided "as-is", on a best-effort basis. Queries may work better or worse than expected, your mileage may vary. It is up to each customer to analyze each query individually and understand if that is enough for their specific needs.
SELECT *
FROM ( SELECT B.FULL_KEY,
B.TITLE,
CAST((XPATH('//branches/branchRemovalCleanUpEnabled/text()', CAST(BD.XML_DEFINITION_DATA AS XML)))[1] AS TEXT)::BOOLEAN AS "Branch_Removal_Cleanup",
CAST((XPATH('//branches/inactiveBranchCleanupEnabled/text()', CAST(BD.XML_DEFINITION_DATA AS XML)))[1] AS TEXT)::BOOLEAN AS "Inactive_Branch_Removal",
CAST((XPATH('//branches/removalCleanupPeriodInDays/text()', CAST(BD.XML_DEFINITION_DATA AS XML)))[1] AS TEXT)::INT AS "Removal_Cleanup In Days",
CAST((XPATH('//branches/inactivityInDays/text()', CAST(BD.XML_DEFINITION_DATA AS XML)))[1] AS TEXT)::INT AS "Inactivity_in_Days"
FROM BUILD B
JOIN BUILD_DEFINITION BD
ON BD.BUILD_ID = B.BUILD_ID
WHERE B.BUILD_TYPE = 'CHAIN' ) A
WHERE (
"Branch_Removal_Cleanup" IS FALSE
OR "Inactive_Branch_Removal" IS FALSE )
ORDER BY FULL_KEY
Example output
Full_key | title | Branch_Removal_Cleanup | Inactive_Branch_Removal | Removal_Cleanup In Days | Inactivity_in_Days |
---|---|---|---|---|---|
ABC-AG | Artifact Generator | TRUE | FALSE | 8 | 30 |
ABC-DFG | DFG | TRUE | FALSE | 2 | 30 |
ABC-EL | ELASTIC | FALSE | FALSE | 7 | 30 |
ABC-FAIL | FAIL | FALSE | FALSE | 7 | 30 |
ABC-WIN | WIN | FALSE | FALSE | 7 | 30 |
DEF-AD | Additional | FALSE | FALSE | 7 | 30 |
DEF-BB6 | BB6 | FALSE | FALSE | 12 | 9 |
DEF-BIG | BIG | FALSE | FALSE | 7 | 30 |
DEF-BREAK | BREAK | FALSE | FALSE | 7 | 30 |
DEF-DEF | DEF | FALSE | FALSE | 7 | 30 |
DEF-GRAD | GRAD | FALSE | FALSE | 7 | 30 |
DEF-JIRA | Jira | FALSE | FALSE | 7 | 30 |
DEF-TS | TEST Specs | TRUE | FALSE | 2 | 30 |
After having a list of Plans with disabled Branch clean-up settings, you can either update them by editing each Plan under the "Branches" tab or use Specs for a programmatic change.
If the provided SQL fails with XML syntax errors, try the following query that doesn't use XPATH. It will return Branch_Removal_Cleanup and Inactive_Branch_Removal. Finding each policy numbers will need to be parsed on each Plan settings individually:
SELECT *
FROM (SELECT B.FULL_KEY,
B.TITLE,
CASE
WHEN BD.XML_DEFINITION_DATA LIKE
'%<branchRemovalCleanUpEnabled>false</branchRemovalCleanUpEnabled>%' THEN 'false'
ELSE 'true'
END AS "Branch_Removal_Cleanup",
CASE
WHEN BD.XML_DEFINITION_DATA LIKE
'%<inactiveBranchCleanupEnabled>false</inactiveBranchCleanupEnabled>%' THEN 'false'
ELSE 'true'
END AS "Inactive_Branch_Removal"
FROM BUILD B
JOIN BUILD_DEFINITION BD
ON B.BUILD_ID = BD.BUILD_ID
WHERE B.MARKED_FOR_DELETION IS NOT NULL
AND B.BUILD_TYPE = 'CHAIN') A
WHERE ( "Branch_Removal_Cleanup" = 'false'
OR "Inactive_Branch_Removal" = 'false' )
ORDER BY FULL_KEY