Bamboo: how to find if any build agent is running from script

I am relatively new to Bamboo engine. I am writing a script to blow away a cache on each build agent. However, before blowing away cache, I need to check if any build agent is performing any build. If yes, then my script will wait till it finished its job else it will straight away remove cache. Not sure how to check build-agents status from scripts.

Thanks.

2 answers

0 votes

Hello Ninad,

If possible, could you please provide more information regarding on the cache you are referring to?

Please, find below ways to clean working directory, if this is what you are looking for.

image2016-12-21 20:29:7.png

image2016-12-21 20:31:19.png

Kind regards,

Rafael

Hello Rafael,

Thanks for responding. I am aware of the options you have provided in your response. These options will clear cache for all my builds. However, I need to do the clear my cache (or any other directory) only on certain event which I am going to control using a script. 

Please find the snapshot herein to give you a better idea about my implementation. The highlighted line is the place where I need to check if my agent is currently idle or its working.

Just to give you a brief idea about this implementation: I have 10 build agents and on certain events, I need to clear sstate_cache ( other directories) from all the existing build agents. However, I need to make sure I am cleaning build agent only if the build agent is ideal at that time else I will wait till it get ideal.

Screen Shot 2016-12-21 at 2.52.02 PM.png

 

If you are running a build against those 10 Bamboo agents, builds will only run if the the agent is available, otherwise will be sitting on queue. Once their are taken from queue, you could add a Script task to be executed as the first thing in the JOB to delete the caching you are referring to.

You could also run the following REST API call:

curl -k -u BAMBOO_ADMIN -H "Content-type: application/json" -X GET BAMBOO_BASE_URL/rest/api/latest/agent

As a response, you should get:

[{
    "id": 4718593,
    "name": "Agent A",
    "type": "REMOTE",
    "active": false,
    "enabled": true,
    "busy": false
}, {
    "id": 163841,
    "name": "Default Agent",
    "type": "LOCAL",
    "active": true,
    "enabled": true,
    "busy": true
}]

You should be looking at the busy state, if it is true, the agent in question is building something.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Monday in Confluence

Organizing your space just got easier - Page Tree Drag & Drop is here

Hi Community! I’m Elaine, Confluence Product Manager. You may have read my earlier post about page tree in space navigation sidebar. I'm excited to share another improvement that helps you organize ...

101 views 3 4
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you