How to list the last modification time for all branches in all repositories in Bitbucket Data Center using a script

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

Summary

This knowledge base article covers how we can list the last modification date of all branches within all repositories within Bitbucket Data Center.

Solution

Prerequisites

You will need to have filesystem access to the $BITBUCKET_HOME directory

Bitbucket Data Center will store raw Git repositories under $BITBUCKET_HOME/shared/data/repositories/\#. We can obtain the date and branch name from Git using the following command:

git for-each-ref --sort=-committerdate:iso8601 --format='%(committerdate:iso8601)%09%(refname)' refs/heads

To list this for all repositories we can loop using the following bash script:

#!/bin/bash

cd $BITBUCKET_HOME/shared/data/repositories
for rep in [0-9]*
do
   cd $rep
   grep -E 'project|repository' repository-config
   git for-each-ref --sort=-committerdate:iso8601 --format='%(committerdate:iso8601)%09%(refname)' refs/heads
   cd ..
done

This will produce output similar to the following:

project = TST

repository = testing

2021-07-28 09:29:37 +1000 refs/heads/Development

2020-10-01 04:31:31 +0000 refs/heads/master

2020-10-01 04:30:48 +0000 refs/heads/Staging

project = RW

repository = realwork

2021-01-20 20:36:13 +1100 refs/heads/Development

2018-10-24 09:19:23 +1100 refs/heads/master

2018-10-24 09:18:49 +1100 refs/heads/Staging

project = CP

repository = wombat

2019-02-28 13:10:06 +1100 refs/heads/master

...



Last modified on Apr 19, 2022

Was this helpful?

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