How to identify which repository triggered a build

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. 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

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!

On a build plan set up with multiple repositories, depending on the workflow, it might be useful to know which of the repositories triggered each specific build. Although this information is available in the UI (Build Summary > Code Commit section), some scenarios might benefit from having that information during build time.

Solution

Bamboo has variables that store both the current and previous revision of each repository on a given plan. We can use that in a Script Task to determine which repository had its contents changed (and thus triggered the build).

Script Task

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #!/bin/bash echo =========================================================== i=1 while true do repoRevision='bamboo_planRepository_'$i'_revision' prevRepoRevision='bamboo_planRepository_'$i'_previousRevision' if [ -z "${!repoRevision}" ]; then break else repoRevision=$repoRevision prevRepoRevision=$prevRepoRevision if [ ${!repoRevision} != ${!prevRepoRevision} ] then repoName='bamboo_planRepository_'$i'_name' repoBranch='bamboo_planRepository_'$i'_branch' echo 'The repository '${!repoName}' ('${!repoBranch}') was updated' echo 'Revision: '${!repoRevision} echo 'Previous revision: '${!prevRepoRevision} fi i=$(( $i + 1 )) fi done echo ===========================================================

You might need to update the script to any specific nuances your environment might have, which can include translating it into a different syntax.

The build logs will then show the following:

Build logs

1 2 3 4 5 =========================================================== 29-Oct-2021 17:45:05 The repository MY-REPOSITORY (master-branch) was updated 29-Oct-2021 17:45:05 Revision: 4b8fa9bece5a2c95c1abea7ce760321421cec36e 29-Oct-2021 17:45:05 Previous revision: ea10759cc579f9bb9966f1b75500d33e7e18d342 ===========================================================

Going further

You can do some cool things with that information. For example, you can inject the ${!repoName} value (or any of the other script variables) into a variable and use it in the conditional checkout tasks. ℹ️ Please see the Inject Bamboo Variables Task documentation. The variable can then be integrated into the workflow on the following tasks & stages of a build plan.

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.