How to bulk update the "After branch inactivity in repository" setting in Bamboo

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

This article explains how to update the "After branch inactivity in repository" setting located inside the Plan > Default plan configuration > Branches page directly in the database. This option is part of the automatic branch management settings and is used by Bamboo to determine when to delete a plan branch after it has gone inactive in the remote repository.

Environment

Bamboo versions 7.0 and higher.

Solution

It is currently not possible to bulk update this setting across different plans from the user interface. The only alternative is to make this change directly in the database. In the following examples we will demonstrate how to identify and enable/disable the "After branch inactivity in repository" setting.

Always back up your data before performing any modifications to the database. If possible, test any alter, insert, update, or delete SQL commands on a staging server first.

The following SQL statements have been tested on PostgreSQL and may need to be adjusted to work on different database engines.

Disable the "After branch inactivity in repository" option

  1. Get a list of all the plans with Plan > Default plan configuration > Branches > Delete plan branch > After branch inactivity in repository enabled:

    SELECT build.full_key,
           build_definition.build_id,
           build.created_date,
           build.updated_date
      FROM build
      JOIN build_definition
        ON build.build_id = build_definition.build_id
     WHERE build.marked_for_deletion IS NOT NULL
       AND build_definition.xml_definition_data LIKE '%<inactiveBranchCleanupEnabled>true</inactiveBranchCleanupEnabled>%'
       AND build_type = 'CHAIN'
     ORDER BY updated_date ASC;
  2. Take note of the BUILD_ID from the plans that you want to disable the "After branch inactivity in repository" option.

  3. Stop Bamboo.

  4. Replace the BUILD_ID in the following update query with the ID of plan(s) you want to update:

    UPDATE build_definition
       SET xml_definition_data = REPLACE(xml_definition_data,'<inactiveBranchCleanupEnabled>true</inactiveBranchCleanupEnabled>','<inactiveBranchCleanupEnabled>false</inactiveBranchCleanupEnabled>')
     WHERE build_definition.build_id IN ('BUILD_ID'); 

     (info) You can add a list of BUILD_IDs separated by comma if you're looking to update multiple plans (e.g. '1234','5678','9012' and etc).

  5. Run the update query to disable the option.
  6. Start Bamboo.

Enable the "After branch inactivity in repository" option

  1. Get a list of all the plans with Plan > Default plan configuration > Branches > Delete plan branch > After branch inactivity in repository disabled:

    SELECT build.full_key,
           build_definition.build_id,
           build.created_date,
           build.updated_date
      FROM build
      JOIN build_definition
        ON build.build_id = build_definition.build_id
     WHERE build.marked_for_deletion IS NOT NULL
       AND build_definition.xml_definition_data LIKE '%<inactiveBranchCleanupEnabled>false</inactiveBranchCleanupEnabled>%'
       AND build_type = 'CHAIN'
     ORDER BY updated_date ASC;
  2. Take note of the BUILD_ID from the plans that you want to enable the "After branch inactivity in repository" option.

  3. Stop Bamboo.

  4. Replace the BUILD_ID in the following update query with the ID of plan(s) you want to update:

    UPDATE build_definition
       SET xml_definition_data = REPLACE(xml_definition_data,'<inactiveBranchCleanupEnabled>false</inactiveBranchCleanupEnabled>','<inactiveBranchCleanupEnabled>true</inactiveBranchCleanupEnabled>')
     WHERE build_definition.build_id IN ('BUILD_ID'); 

    (info) You can add a list of BUILD_IDs separated by comma if you're looking to update multiple plans (e.g. '1234','5678','9012' and etc).

  5. Replace the BUILD_ID in the following update query with the ID of plan(s) you want to update and yourInactiveDays with the number of days Bamboo should wait before deleting an inactive plan branch (e.g. 10, 30, 45 and etc)

    UPDATE build_definition
       SET xml_definition_data = Regexp_replace(xml_definition_data,'<inactivityInDays>\d+</inactivityInDays>','<inactivityInDays>yourInactiveDays</inactivityInDays>','g')
     WHERE build_definition.build_id IN ('BUILD_ID');
  6. Run the update queries to enable the "After branch inactivity in repository" option and set the number of days.
  7. Start Bamboo.
Last modified on Jun 17, 2022

Was this helpful?

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