Issue
How do I list projects/job names in system Groovy only on master node?
To be more specific:
I need only list of jobs which runs on master. I don't want output any job which runs on slave nodes.
Solution
How to list all jobs that has run on master, not that will be run on master... This script only checks the jobs that has actually run and isnt't removed/cleaned up.
http://javadoc.jenkins-ci.org/hudson/model/AbstractBuild.html#getBuiltOnStr()
import hudson.model.*
jenkins = Hudson.instance
items = jenkins.items
for (item in items){
def job = item.getLastBuild()
if(job != null){
if(job.getBuiltOnStr() == null || job.getBuiltOnStr() == "")
println "Built on master: " + job.toString()
}
}
Answered By - MaTePe
Answer Checked By - David Goodson (JavaFixing Volunteer)