stack
stack

Reputation: 17

How to get the 'view' name from jenkins?

There is a 'view' create by name 'Test_View' and a job created under 'Test_View' is 'Test_Job'.

Test_View >> Test_Job

In Test_Job, I am trying to print the name_of_the_view (i.e., 'Test_View').

How do I retrieve the view name in Test_Job ?

I don't think so, if there are any environment variables available.

Can I do it from groovy script ?

Upvotes: 0

Views: 1801

Answers (1)

np2807
np2807

Reputation: 1160

I think it is not possible using Jenkins UI but with the Groovy you can extract, instance.view will enable to read view configured into Jenkins, but that even is only possible with iteration (using for loop) for all views in Jenkins.

found_views = []

views = hudson.model.Hudson.instance.views

for (view in views){
  for (job in view.items) {
    if (job.name.equals(Test_Job)){
      Test_View << view.name
    } // if
  } // for view.items 
}// for view

Also have a look in HERE

Upvotes: 1

Related Questions