Markus commented on New Feature JENKINS-18536

For anyone that may need the same feature. Our current work-around is a rather messy groovy script added to Upstream:

CancelDownstreamQueue.groovy
import hudson.model.*

Jenkins = Hudson.instance
def q = Jenkins.instance.queue;

if ( args.length != 2 ) {
  println "ERROR - CancelDownstreamQueue.groovy - Scripts needs two arguments. Own job name and part of downstream job name to search for. Do not know if wildcards are supported." 
} else {
  println("Search for downstream jobs from " + args[0] + " whose name contains " + args[1]);
  def thisjob = Jenkins.getInstance().getItemByFullName(args[0]);
  if (thisjob == null) {
    println("ERROR - CancelDownstreamQueue.groovy - Could not find this job");
  }else{  
    //println(thisjob.getDownstreamProjects())
    List<AbstractProject> childs = thisjob.getDownstreamProjects()
    if (childs == null) {
     println("ERROR - CancelDownstreamQueue.groovy - childs is null");
    }else{
      for (Iterator<AbstractProject> iterator = childs.iterator(); iterator.hasNext();) {
        AbstractProject child = iterator.next();
        if (child.getFullName().contains(args[1])) {
          println("  Found downstream job " + child.getFullName() + ". Searching for queued items");
          q.items.findAll { it.task.name.equals(child.getFullName()) }.each {
            println("    Cancelling queued " + it.task.getDisplayName());
            q.cancel(it.task);
          }
        } else {
          println("  Skipping " + child.getFullName());
        }
      }
    }
  }
  println("Done");
}

But the script is not 100% stable. It happens to fail (hangs or generates a java.lang.NegativeArraySizeException).
The script is started like this:

java -jar jenkins-cli.jar -s http://jenkins:8080/ groovy ./CancelDownstreamQueue.groovy $JOB_NAME SearchStringForJobsToCancel
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira

--
You received this message because you are subscribed to the Google Groups "Jenkins Issues" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply via email to