I would like to be able to make adjustments to the build queue, which can include adding to it, removing from it, and changing the order of things that are in it, from within a build trigger.
The specific order of operations in the build trigger might be something like:
1) Add new tasks to the queue (BuildPromotion.addToQueue)
2) Get all queued tasks (BuildQueue.getItems)
3) Re-order within queue (BuildQueue.applyOrdering)
4) Remove existing tasks from the queue (BuildQueue.removeItems)
Basically, what I am trying to attempt is to have a trigger actually replace tasks in the queue with tasks that are slightly different, (and have these newly created tasks queued in the same place as the old tasks).
Things appear to be working, but I have a couple of questions about doing this:
1) Is it actually safe to directly change the queue from within a build trigger?
2) Each individual operation seems to be atomic, but I have a hunch that the set of operations is not atomic. i.e. Within the context of a build trigger, is it possible (if improbable) for tasks to be added or removed from the queue in between performing calls to BuildQueue, BuildPromotion.addToQueue, or SQueuedBuild.getOrderNumber? If so, is there a way to do something like this atomically (like locking the queue temporarily)?
seemed relevant, though not the exact same situation as what I am attempting to do.