Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Cancel queued builds and aborting executing builds using Groovy for QuickBuild. #3758

shayan ·

Hi, anyone can help me, if you want to run only the newest job of same project from the build queue and cancel other: am using this but its not working.

//Find items in queue that match <project name>
def queue = q.items.findAll { it.task.name.startsWith('sample_project') }
//get all jobs id to list
def queue_list = []
queue.each { queue_list.add(it.getId()) }
//sort id's, remove last one - in order to keep the newest job, cancel the rest
queue_list.sort().take(queue_list.size() - 1).each { q.doCancelItem(it) }

  • replies 2
  • views 1393
  • stars 1
robinshen ADMIN ·

Run below script on QB server will do the job:

groovy:
def interestingProjectId = system.configurationManager.get("path/to/interesting/project").id;

def first = true;
for (each in system.buildEngine.getBuildRequests(interestingProjectId)) {
  if (first) {
    first = true;
  } else {
    system.buildEngine.cancelRequest(each.id);
  } 
}
#4
robinshen added the scripts label