Jenkins pipeline implementing a queue to execute parallel build jobs depending on AWS resource availability
I want to implement a pipeline in which I want to execute jobs parallel inside a stage block using a loop. The execution of the job depends on the availability of AWS resources and therefore while all resources are utilized, the next set of jobs should be added to a queue and then when the resources are released by the currently running jobs, jobs should be dispatched one by one from the queue until the queue is empty.
Is there a way to check the resource availability and dispatch a job from the queue after each triggered job has completed? Can waitUntil be used for this and if so how?