List all jobs, which were running on a specific slave node
Asked Answered
E

3

6

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.

Egin answered 17/6, 2015 at 5:1 Comment(2)
In terms of multi-configuration project, those "sub-jobs" are called "configurations". Could you please show us config of your axis in "Configuration Matrix" section (job configuration)?Ormond
Hi Vitalii, thank you for your comment. I'm not quite sure, why you need this information, because I'm just searching for a plugin, which lists the job history by a different point of view (sorted by nodes). But our configuration has one "Slaves" axis, which actually ensures, that the "matrix-configurations" (in my terms "sub-jobs" ;-)) are spread to slaves marked with a given label. In addition, we have five "User-defined" axes to vary our device configuration.Egin
O
3

You can use Description Setter Plugin like the following:

enter image description here

Then you will have node label in the description of each build:

enter image description here

Ormond answered 17/6, 2015 at 7:8 Comment(2)
Thank you for this suggestion. Unfortunately I can not use this solution. We already use the description for an other purposeEgin
@FlowReiSer Just let you know, description can have multiple values. But yes, that is not a perfect way to report.Ormond
O
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.

Ormond answered 18/6, 2015 at 7:26 Comment(3)
Hi Vitalii, thank you for your help. I will use your solution, if I can not find any other way. It is definitively better than to check all the logs manually :-)Egin
@Vitalii Elenhaupt, is there a way to list projects (not jobs have been run) currently restricted to a particular node? We want to get ride of some nodes, want to notify projects using these nodes.Ari
If you get the groovy.lang.MissingPropertyException: No such property: builtOnStr for class: org.jenkinsci.plugins.workflow.job.WorkflowRun error, here is my "no so robust" solution https://mcmap.net/q/1776537/-list-all-jenkins-builds-grouped-by-nodeSleave
K
2

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())
    }
  }
}
Kittykitwe answered 28/5, 2018 at 14:52 Comment(1)
This seems to answer "which node the job is assigned to", and does not work with pipeline jobs where node is assigned during run time.Nettlesome

© 2022 - 2024 — McMap. All rights reserved.