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 vote

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published May 18, 2017 in Bamboo

FAQ: How to Upgrade Bamboo Server

Bamboo 5.9 will no longer be supported after June 12, 2017. What does this mean? As part of our End of Life policy, Atlassian supports major versions for two years after the first major iteratio...

1,568 views 0 6
Read article

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