Bamboo : How to execute some logic if job is cancelled or fails
Asked Answered
M

1

22

I'm in a process of writing a Bamboo plugin, the bulk of which is complete.

The plugin works by starting a remote process off via a post request to a server and then polling the same server until it gets a message saying the process has completed or an error occurred - this part works.

I would like to add some extra logic where I can notify this server if the user cancels the job, however I'm unsure of how to go about this.

I have played about with creating another task which runs as a final task, however I don't know how to detect if any of the previous tasks failed or were cancelled.

I have tried using List<TaskResult> taskResults = taskContext.getBuildContext().getBuildResult().getTaskResults(); to get a list of the previous Task's results, however this always appears to return 0 Task Results.

I have also tried using a Post-Build Completed Action Module, however I'm unsure how I would add this to a job and the documentation on this has me slightly mystified.

If anyone could help me in the right direction I would appreciate it.

Mantis answered 29/8, 2013 at 14:43 Comment(3)
I think you should look at just creating an event listener: developer.atlassian.com/display/BAMBOODEV/… There's already an event there you can listen to docs.atlassian.com/atlassian-bamboo/2.7/com/atlassian/bamboo/…Heirloom
@bScutt: you ll probably find more answers on answers.atlassian.com rather than posting here, but fogedi is correct. Register a listener, and listen for the BuildCanceledEvent, and post the appropriate request to the service(s) that the user cancelled.Jenjena
@Mantis Atlassian Answers is a better place for Atlassian related questions: answers.atlassian.com (Note: as they currently migrate to another platform, you may not be able to post there)Chrysoberyl
S
7

From reading what you had written, I think that using an event listener is definitely the correct way to approach your problem. Below I have provided an image of my own creation that seems to describe what you have constructed and that shows where it might be best to place the event listener.

Essentially, the client of yours will issue a cancel notification to the server via its network controller mechanism. The server will then receive that cancelation notification via its network controller which is already connected to the client via some network protocol (I am assuming TCP). When that cancellation notification from the client network controller reaches the network controller of the server, the event listener in the network controller of the server will then signal the server build manager to terminate the remote build.

Diagram of your program enter image description here

I hope this helps.

Spondaic answered 26/9, 2014 at 16:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.