jenkins_api_client icon indicating copy to clipboard operation
jenkins_api_client copied to clipboard

Feature request: Add support for folders plugin

Open knumor opened this issue 9 years ago • 12 comments
trafficstars

It would be nice if support could be added for the Cloudbees Folder plugin, so that list_by_status and friends could traverse the folders with "_class": "com.cloudbees.hudson.plugins.folder.Folder".

knumor avatar Jun 24 '16 14:06 knumor

I was thinking of trying to add support for this myself in a pull request. But I was curious, one of the python libraries that talks to Jenkins handles folders by passing a depth param into their get_jobs() method. Does that also make sense here or does someone have a different suggestion for how to handle this?

agargiulo avatar Sep 06 '16 16:09 agargiulo

I added "recursive folder" support to https://github.com/jenkinsci/puppet-jenkins earlier this year via a groovy snippet that is feed into CLI.jar. I spent about an hour this morning attempting to implement similar recursion against the REST API via this gem. For a moderate number of jobs folders (38) on an ec2 c4.large instance, uploading a groovy snippet is approximately a factor of 7 faster than walking the REST API.

I would really like to see Cloudbees folder support merged into this gem... what do folks feel is the best way to proceed?

Test code + benchmark: https://gist.github.com/jhoblitt/5f812cba39f0ec3c2e01f00d97d379a2

jhoblitt avatar Dec 04 '16 18:12 jhoblitt

@jhoblitt Can I put this code in a PR so we can use it under the terms in this gems LICENCE?

sahal avatar Jan 25 '17 22:01 sahal

@sahal Absolutely.

jhoblitt avatar Jan 25 '17 22:01 jhoblitt

I think there are multiple possible solutions to this.

Code is committed (ready for further testing)

  • https://github.com/sahal/jenkins_api_client/tree/feature/fix-exists - This branch allows you to search for explicit job names at the root as well as explicit job names (not sure if anyone was using exists? with the regex capability of the list method, but that is no longer available with this branch)

The following is basically copied from jhoblitt's gist listed above and incorporated in job.rb:

  • https://github.com/sahal/jenkins_api_client/tree/feature/list-jobs-using-dsl - pretty fast as it uses the dsl to run jhoblitt's script
  • https://github.com/sahal/jenkins_api_client/tree/feature/add-list-all-jobs - really really slow (see jhoblitt's tests above for details)

Code is not committed yet

I also think we could possibly use something like this in the list() method in job.rb:

response_json = JSON.parse(@client.api_get_request("/api/json","tree=jobs[jobs[jobs[jobs[jobs[jobs[jobs[jobs[jobs[jobs[jobs[url,displayName,name],url,displayName,name],url,displayName,name],url,displayName,name],url,displayName,name],url,displayName,name],url,displayName,name],url,displayName,name],url,displayName,name],url,displayName,name],url,displayName,name]","",false))

This seems to be just as fast as the DSL script that jhoblitt wrote, but:

  • It requires more parsing because the JSON returned is nested. (also this is only 11 levels deep right now)
  • It looks really ugly no matter how you look at it.

I'm sure that neither of these are complete solutions, but wanted to post code here to get some feedback.

sahal avatar Feb 23 '17 21:02 sahal

I updated @sahal's PR with fixes to the tests, plus a new test to ensure that we don't get false positives because of folder names.

dayer4b avatar Apr 04 '17 21:04 dayer4b

I just gave @sahal's nested search query a work and it seems to work for me (I am awed and somewhat horrified...). If this is a viable approach, it may be less fragile than shipping groovy snippets. However, I think this is a badly needed feature and will support which ever method is most likely to be merged.

jhoblitt avatar Apr 04 '17 21:04 jhoblitt

@arangamani - I sent you an email but haven't heard back. I'd like to help you maintain this repo; if you want to give me access to review and approve and merge, I can help look through some of these PRs and issues to see if we can merge some in and add needed features.

katelovescode avatar Nov 02 '17 17:11 katelovescode

@katelovescode I apologize for not responding promptly to your email. I've added you as a collaborator now. I'd appreciate if you can mention me in any discussions.

arangamani avatar Nov 02 '17 22:11 arangamani

Thanks, @arangamani ! I'm looking forward to helping out!

katelovescode avatar Nov 03 '17 00:11 katelovescode

hi, any movement on support for folders and jobs within folders? I'm using Jenkins 2.175

I've just started playing around with the gem and discovered that i can only list the top level jobs and folders, whereas i need to be able to search or at least access nested jobs within folders. It's a bit of a blocker for me to use this lib.

edk avatar Oct 25 '19 19:10 edk

@katelovescode @arangamani I've raisd a PR to add a feature of job listing by specifing folders into APIs. Please have a look. This feature is very important and many people would be looking out for this.

swapnils19 avatar Apr 19 '20 12:04 swapnils19