Automating Bamboo Agent Dedications
Asked by Helen Griffiths:

Good afternoon

I was wondering whether anyone had / has a secret formula for automating Bamboo agent dedications. As a Support Function, we had to restrict what the users can do due to security. Unfortunately, this means every time an Agent needs approving, it also needs dedicating. If the Agent previously had dedications, we have to manually go in and add them. With some Agents have 200+ dedications, this causes a lot of wasted time waiting for the list to populate from the search field (last time I did this it took over two hours!)

Has anyone done anything like this before? ...and if so, how did you do it?

Any help would be gratefully appreciated :)


Answers:
author: Steffen Opel _Utoolity_
body: I have not done this before, but it's an interesting challenge :)  

To expand on [@Alexey Chystoprudov](/t5/user/viewprofilepage/user-id/781646)'s answer (+1), here's how I'd try to tackle an end to end automation based on our own (commercial) add-on (which currently requires that you have an AWS account yourself):

1. Implement the code to dedicate the agents via the REST API, ideally in a language natively supported by [AWS Lambda](https://aws.amazon.com/lambda/) (currently C#, Java, Node.js, Python, though most others can be used via shims too)
2. Once you are comfortable that you can achieve your goal via REST, convert the code into a Lambda function (there are many frameworks to help with this, most popular is [Serverless](https://serverless.com/))
3. Install Atlassian Lab's [Bamboo Agent Notifications](https://marketplace.atlassian.com/plugins/com.atlassianlab.bamboo.plugins.bamboo-agent-notification-plugin/server/overview) add-on
4. Install Utoolity's [Automation with AWS (Bamboo)](https://marketplace.atlassian.com/plugins/net.utoolity.atlassian.bamboo.automation-with-aws-bamboo/server/overview) add-on
5. Configure a global 'Notify on remote/elastic agents online status' notification to trigger an 'Automate with AWS' recipient with an [Invoke Lambda Function](https://utoolity.atlassian.net/wiki/display/UAAWS/Using+the+Invoke+Lambda+Function+action) action configured to call the function you deployed in step 2 (for more complex workflows you could also use the [Start Step Functions Execution](https://utoolity.atlassian.net/wiki/display/UAAWS/Using+the+Start+Step+Functions+Execution+action) action, which e.g. allows to await another event before proceeding with an approval or dedication)

**Caveat**

Please note one important caveat regarding 5:

The 'Automate with AWS' notification recipient provides a [$notification](https://utoolity.atlassian.net/wiki/display/UAAWS/Notification) entity variable for access to the default Bamboo templates, which can be used to parse the required info out of the message (e.g. the elastic instance ID), though not everything you need might be available within the agent notification already.  

However, we are also offering variables like [$resultSummary](https://utoolity.atlassian.net/wiki/spaces/UAAWS/pages/208568380/ResultsSummary) (incl. 'buildAgentId') and [$deploymentResult](https://utoolity.atlassian.net/wiki/spaces/UAAWS/pages/208666687/DeploymentResult) (incl. 'agentId') so that you can compose a payload with the exact information you need. Similarly we *should* be able to provide an '$agent' variable that exposes the details available via the [AgentRegisteredEvent](https://docs.atlassian.com/atlassian-bamboo/latest/com/atlassian/bamboo/event/agent/AgentRegisteredEvent.html), i.e. the fields in a [PipelineDefinition](https://docs.atlassian.com/atlassian-bamboo/latest/com/atlassian/bamboo/buildqueue/PipelineDefinition.html) - let me know if you'd be interested in this approach and I'd be happy to explore it with my team.

comments: author: elmoenco
body: Thanks [@Steffen Opel _Utoolity_](/t5/user/viewprofilepage/user-id/781567) . For a customer I'm trying to improve Bamboo self-service in a multi customer / AWS account environment. Automating the agent dedication to a project is mandatory. It's unfortunate that Bamboo doesn't have that functionality.


author: Alexey Chystoprudov
body: There's REST endpoint to manage agent/elastic image dedication: [https://docs.atlassian.com/bamboo/REST/6.1.0/#d2e2434](https://docs.atlassian.com/bamboo/REST/6.1.0/#d2e2434?)


Tags: agent