Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

 

rsperafico Atlassian Team Dec 21, 2016

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.

I was trying to use this api for very similar semaphoring reasons but to my horror it turns out that it can be out of sync for ~30-60 seconds (we are using Bamboo 6.6.2). I mean I start a build which sleeps for 60 seconds and start to poll 

BAMBOO_BASE_URL/rest/api/latest/agent

And it says for the particular agent "busy": false for ~30 seconds before it starts to report true. 

The same goes after the end of the build. How to ask the bamboo server nicely to report the most recent state? 

0 votes
rsperafico Atlassian Team Dec 21, 2016

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bamboo

Bamboo Data Center 8.1 is now available

G’day Bamboo customers, Bamboo DC 8.1 is now available with it the following features and programs: SAML 2.0, OpenID Connect, and Crowd SSO In order to help admins with a simplified user manage...

200 views 0 4
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you