VSK
VSK

Reputation: 469

Find view name from jenkins GUI given the job details

I have few hundreds of jenkins jobs all classified into different views based on different projects. So, I already have around 30+ views in Jenkins. My question is, Given a jenkins job name can I find out which View it is classified into.

Upvotes: 3

Views: 3182

Answers (2)

Vitalii Elenhaupt
Vitalii Elenhaupt

Reputation: 7326

That is not possible using only Jenkins UI. But you can do this with Jenkins script console.

Here is a groovy sample. A job can be included in one, two or more views. So, basically, you can iterate through all views and check whether your job belongs to a concrete view or not. Set your job name and execute it in your script console:

job_name = 'YOUR_JOB_NAME'
found_views = []

views = hudson.model.Hudson.instance.views

for (view in views){
  for (job in view.items) {
    if (job.name.equals(job_name)){
      found_views << view.name
    }
  }
}

println String.format("Job '%s' is included to: %s", 
                  job_name, 
                  found_views.sort().join(', '))

// If such job exists, you will have something like this:
// Job 'YOUR_JOB_NAME' is included to: All, ...

Upvotes: 7

acanby
acanby

Reputation: 2993

I don't think this is possible. Remember that while your configuration might have a 1:1 mapping, it is entirely possible that jobs fit into many views, either via a regex match or selected explicitly.

Additionally, and depending on configuration, it is possible for users to create their own views. This could introduce more noise...

Upvotes: 0

Related Questions