问题
On our Jenkins master a Multi-configuration project is used to spread a highly parallel task on many slaves which actually do the work.
Now I would like to list all jobs, which were running on a specific slave node. Is there a way to achieve this? I see only all matrix sub jobs for one matrix parent job in a big table. Or I can list the history of a single sub job. But if I want to get the connection to the node, where the job was running on, I always have to check the logs.
回答1:
You can use Description Setter Plugin like the following:
Then you will have node label in the description of each build:
回答2:
Now I would like to list all jobs, which were running on a specific slave node.
I didn't find any existed plugin to solve the problem. But you can automate it a bit with a Jenkins Script Console. Here is a simple groovy script that iterates through job's builds and checks whether that build was built on a concrete node:
def jobs = hudson.model.Hudson.instance.items
nodeName = 'YOUR_NODE_NAME'
jobs.each { job ->
urls = []
job.builds.each { build ->
nodeName == build.builtOnStr && urls << build.absoluteUrl
}
urls && println("${job.name}\n\t${urls.sort().join('\n\t')}")
}
Sample output:
JOB1
JENKINS_URL/job/JOB1/11/
JOB2
JENKINS_URL/job/JOB2/59/
JENKINS_URL/job/JOB2/60/
JENKINS_URL/job/JOB2/61/
...
If you would like to go further, you could use it to prepare some clickable html report. First that comes to the mind is to send emails with Email-ext plugin.
Note: that script will not work with nodeName = 'master'
. This should be expected 'cause master, actually, is not a node.
回答3:
I've solved it like this using the script console
for (item in hudson.model.Hudson.getInstance().getItems()) {
if (item instanceof hudson.model.FreeStyleProject) {
if (item.getAssignedLabel() != null && item.getAssignedLabel().getName() == 'master') {
println(item.getName() + " " + item.getAssignedLabel())
}
}
}
来源:https://stackoverflow.com/questions/30882670/list-all-jobs-which-were-running-on-a-specific-slave-node