Bamboo planbranch setting to prevent deletion pendant in database
Asked by HeWi:

I wonder where in the Bamboo database the setting "**Clean up plan branch automatically**" is stored while creating a new planbranch?

(see 2b: <https://confluence.atlassian.com/bamboo/using-plan-branches-289276872.html>)

Is it maybe stored in a local database or xml file instead? The scheduler will not delete planbranches having the option deactivated and I would like to understand how Bamboo does make a decision between different plan branches.


Answers:
author: Eduardo Alvarenga
body: Hello [@HeWi](/t5/user/viewprofilepage/user-id/3583857)

The Plan branch cleanup is defined on the **BUILD_DEFINITION** table in the database as an XML element within XML_DEFINITION_DATA.

```
<cleanup><disabled>true</disabled></cleanup>
```

This query might help you locate that information. Works on PostgreSQL.

```
SELECT B.BUILD_ID,
       B.BUILD_TYPE,
       B.FULL_KEY,
       BMD.BRANCH_NAME AS "branch_name",
       CASE
              WHEN CAST((XPATH('//branchConfiguration/cleanup/disabled/text()',CAST(BD.XML_DEFINITION_DATA AS XML)))[1] AS TEXT) = 'true' THEN 'NO'
              ELSE 'YES'
       END AS BRANCH_CLEANUP
FROM   BUILD B
JOIN   BUILD_DEFINITION BD
ON     B.BUILD_ID = BD.BUILD_ID
JOIN   BRANCH_METADATA BMD
ON     BMD.PLAN_ID = B.BUILD_ID
WHERE  B.BUILD_TYPE = 'CHAIN_BRANCH'
```

Regards,

Eduardo Alvarenga  
Atlassian Support APAC

comments: author: HeWi
body: Ahh, I see, thanks a lot for your reply [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410) , very helpful indeed.

Looking at the column with ntext datatype, it is kind of laborious, if the switch would have to be toggled, I would have to work with temporary tables, doing casting, etc.

Isn't there a simpler way in Bamboo to avoid specific plan branches from getting cleaned up automatically (I don't want to uncheck the planbranches manually)? I have to take two options into consideration:

a) cleanup due to git delete branch

b) cleanup due to branch inactivity

What if I would like to avoid bugfix/ branches from getting cleaned up? Is the only chance to look for bugfix/ branches in the tables and set disabled to true in the XML?


author: Eduardo Alvarenga
body: Hey [@HeWi](/t5/user/viewprofilepage/user-id/3583857)

Thanks for the feedback. Following the [community guidelines](https://community.atlassian.com/t5/custom/page/page-id/rules-of-engagement) please avoid posting different concerns as a follow-up to a question that's been already answered.

If you are satisfied with the first answer please mark it as Accepted and post the next question as a second post and we'll be happy to assist. That eases the web crawler job and enhances indexing (and search) to other users.

Regards,

Eduardo Alvarenga  
Atlassian Support APAC


author: HeWi
body: Hello [@Eduardo Alvarenga](/t5/user/viewprofilepage/user-id/4365410) , thanks for your reply and guideline reference. I've followed your suggestion and created another thread: [Way to stop automatic planbranch cleanup for specific branch types](https://community.atlassian.com/t5/Bamboo-questions/Disable-planbranch-cleanup-in-database-for-specific-branches/qaq-p/2033836#M31466)


Tags: plan