Get list of Jobs in a View

3,783 views
Skip to first unread message

grayaii

unread,
Jun 21, 2011, 4:25:11 PM6/21/11
to jenkins...@googlegroups.com
Is it possible to get a list of jobs that are in a particular "View"
programmatically?

Right now, I'm parsing the config.xml to get this information, but I'm
wondering if there is a cleaner way of getting this information.

Thanks!


--
View this message in context: http://jenkins.361315.n4.nabble.com/Get-list-of-Jobs-in-a-View-tp3615221p3615221.html
Sent from the Jenkins users mailing list archive at Nabble.com.

Dean Yu

unread,
Jun 21, 2011, 5:48:19 PM6/21/11
to jenkins...@googlegroups.com, grayaii
Hi George,
Are you familiar with the remote API[1]?

You can request http://<your server>/view/<view name>/api/xml to get the
list of jobs.

-- Dean

[1] https://wiki.jenkins-ci.org/display/JENKINS/Remote+access+API

Simon Wiest

unread,
Jun 22, 2011, 8:30:56 AM6/22/11
to jenkins...@googlegroups.com
Hi grayaii,

well, it all depends what you understand as 'programmatically' ;O).

Here are some recipes:

1.) Get the list from an external shell command

Get URL http://<SERVER>/view/<VIEW>/api/xml as Dean Yu suggested and
process the XML response in your shell script. Note: You can also get
the same information in JSON via http://<SERVER>/view/<VIEW>/api/json.


2.) Get the list via Jenkins Command Line Interface (CLI)

Run the following CLI command that in turn executes a Groovy script on
the Jenkins master (enter the commmand in one single line):

java -jar jenkins-cli.jar -s http://<SERVER> groovysh
"hudson.model.Hudson.instance.getView('<VIEW>').items.each() { println
it.fullDisplayName }"


3.) Get the list via Groovy from within Jenkins

Run the following snippet in the Scripting console or a Groovy build
step (the latter requires the installation of the Groovy plugin):

hudson.model.Hudson.instance.getView('<VIEW>').items.each() { println
it.fullDisplayName }


4.) Get the list via Java from within a plugin

for(TopLevelItem project :
hudson.model.Hudson.getInstance().getView("<VIEW>").getItems() {
String projectName = project.getFullDisplayName();
[... do something here ...]
}

Cheers,
Simon.
--
grayaii (21.06.2011 22:25):

grayaii

unread,
Nov 4, 2011, 9:44:10 AM11/4/11
to jenkins...@googlegroups.com
Thanks Dean and Simon!
This is exactly what I was looking for! I didn't think it would be so easy!

--
View this message in context: http://jenkins.361315.n4.nabble.com/Get-list-of-Jobs-in-a-View-tp3615221p3990108.html

C Neal

unread,
Sep 4, 2018, 6:33:48 PM9/4/18
to Jenkins Users

Hi!  

 

I am trying to get these scripts to work (#3 or #4).   The problem is that I have "folders" between my views.   And since I don't know what the expected output is, or where the hudson function starts, I can't get any output other than "null" as a response.

I have a "project" folder, then a "Builds" folder, then a version folder.  Under the version folder are the Views.  I have two.

Using the folder method, the path is /Project/Builds/Version.

And on the URL it shows up as .../Project/job/Builds/job/Version

When I am in the URL and in the View, it shows up as:

.../Project/job/Builds/job/Version/view/ViewName

None of this has helped me figure out what the "getView" or other functions return.  

I am trying to make a groovy script to turn off (or on) jobs by view.   I have the one with the folders working.  But the views give me more granularity in to the pieces of our builds.

Can someone point me to the place where the expected output is described?

Thanks,

-Chris

Reply all
Reply to author
Forward
0 new messages