1

I'm freshman in Jenkins. I would like to cancel jobs by it's own label (hundreds) from my Queue of tasks given to slaves: jenkins.model.Jenkins.getInstance().getQueue() so i then could do: items[i].doCancelQueue()

Currently I only know how to do it, by its name: items[i].task.getFullName().

I'm looking for something like this: (when I iterate over Slaves that's just give me list of available labels for a single slave)

for (aSlave in hudson.model.Hudson.instance.slaves) {
    println('Name: ' + aSlave.name);
    println('getLabelString: ' + aSlave.getLabelString());
}

My whole code for deleting jobs by name

import hudson.model.*  

def q = jenkins.model.Jenkins.getInstance().getQueue()   
def items = q.getItems()

if (job_name_fragment == '' && revision == ''){
    println("At least one param is requied")
    return 1
}

def count = 0
for (i=0;i<items.length;i++){  
    if (items[i].task.getName().contains("trunk") || items[i].task.getName().contains("dev")|| items[i].task.getName().contains("Windows")){
        println("Task: " + items[i].task.getName() + " has been skipped")
        continue
    }
    if(job_name_fragment == '' || items[i].task.getFullName().contains(job_name_fragment)){  
        if(revision == '' || items[i].params.contains(revision)){
            println("Task: " + items[i].task.getFullName() + " has been deleted from queue")
            items[i].doCancelQueue()  
            count++;
        }
    }
}
println("")
println("Removed total: " + count + " tasks from queue")

Thanks

2

Found it by myself, if anyone will be interested check:

getAssignedLabel()

in. https://javadoc.jenkins-ci.org/hudson/model/Queue.Item.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.