I considered using the REST API to fetch the labels of the node referenced in the "why" message, but that would be meaningful only if the node had a single label.
For multiple labels, again, I would be unable to tell which one is required.
I wonder how hard it would be to add this element to the REST API. It might be worth checking.
Do you do that remotely? Like injecting a script using the jenkins-cli.jar?
I considered using the REST API to fetch the labels of the node referenced in the "why" message, but that would be meaningful only if the node had a single label.
For multiple labels, again, I would be unable to tell which one is required.I wonder how hard it would be to add this element to the REST API. It might be worth checking.
we use Go but you can use curl or any HTTP client, it is something like thisJENKINS_CRUMB=$(curl --silent "$JENKINS_URL/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,\":\",//crumb)")curl --silent -X POST -H "${JENKINS_CRUMB}" -F "script=<script.groovy" ${JENKINS_URL}/scriptText
yep, this data should be in the API, probably it is a matter of adding an annotation in the Class
import hudson.model.labels.*
Jenkins.instance.queue.items.each {
println ">> Label expression from the pending build:"
def labelFromQueueJob = it.getAssignedLabel()
println "Type: " + labelFromQueueJob.class
println "Expression: " + labelFromQueueJob
println ">> countBuildableItemsFor " + labelFromQueueJob + " : " + Jenkins.instance.queue.countBuildableItemsFor(labelFromQueueJob)
}
println "\n>> Artificially created Label expression:"
LabelExpression artificialLabelExp = new LabelExpression.Or(new LabelAtom("myLabelA"),new LabelAtom("myLabelB"))
println "Type: " + artificialLabelExp.class
println "Expression: " + artificialLabelExp
println ">> countBuildableItemsFor " + artificialLabelExp + " : " + Jenkins.instance.queue.countBuildableItemsFor(artificialLabelExp)
>> Label expression from the pending build: Type: class hudson.model.labels.LabelExpression$Or Expression: myLabelA||myLabelB >> countBuildableItemsFor myLabelA||myLabelB : 1 >> Artificially created Label expression: Type: class hudson.model.labels.LabelExpression$Or Expression: myLabelA||myLabelB >> countBuildableItemsFor myLabelA||myLabelB : 0