Determine which Repo triggered a build
Asked by Ari_Mahpour:

Hello,

I have a build plan that has multiple Git Repos. I also have a polling trigger setup that checks all of them. if any of them have new commits, the build triggers. this works great.

what i need, is a way to determine from environment and/or bamboo variables, which repo triggered the build. currently bamboo gives me every repo's info in the form of "bamboo_planRepository_#_key=value"

This information is available on the build summary page in the commit section as seen below

![trigger.png](/t5/image/serverpage/image-id/57696i3D73865C1F06683E/image-size/large?v=v2&px=999 "trigger.png")


Answers:
author: Daniel Santos
body: Hi [@Ari_Mahpour](/t5/user/viewprofilepage/user-id/988474)

You could get this information by comparing revisions of each source repository. You will need to check the following Bamboo variables:

* **bamboo_planRepository_#_revision**
* **bamboo_planRepository_#_previousRevision**

Considering this could be a pain for you I spent some time to build a bash shell script to do this. It is just an example of how this could be done. Please be careful with a loop like this since it can hold your build in running state forever.

```
echo ===========================================================i=1while truedo   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 ))    fidoneecho ===========================================================
```

??It will not work for Windows. In case you run windows agents you will need to design a similar script for using a windows shell of your preference.

The output should be something like:

```
19-Jun-2019 18:24:24 ===========================================================
19-Jun-2019 18:24:24 The repository javahello (master) was updated
19-Jun-2019 18:24:24 Revision: c3df16947412c1ca69f9e58998d8dd645221f8f5
19-Jun-2019 18:24:24 Previous revision: 55db9a76e132b853c2309aa2cf6c1963e53f06f4
19-Jun-2019 18:24:24 ===========================================================
```

I hope that helps you to achieve what you want.

comments: author: josh bouganim
body: This is awesome. Never noticed that the previous and current rev vars could be the same. Thanks!


author: Daniel Santos
body: You are welcome [@josh bouganim](/t5/user/viewprofilepage/user-id/3344289)  
I'm glad to be helpful.  
Have a good one!


author: alvaro montoya
body: thank you for the solution but the bamboo team should really make these trigger variables available.  

Any chance?

comments: author: Michael Trostle
body: you can put in a request for an enhancement...if it gets that far, I wouldn't expect a quick turn around unfortunately


Tags: build

trigger