Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list matching jobs using dsl #225

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

sahal
Copy link

@sahal sahal commented Feb 24, 2017

Incorporates jhoblitt's groovy script to get a full list of folders. See #210

@dayer4b
Copy link

dayer4b commented Apr 4, 2017

Hi @sahal ! I fixed the tests and added a new one to ensure we don't get false positives from folder names.

@@ -702,17 +702,18 @@ def builder = new groovy.json.JsonBuilder(allInfo)
job_list_json()
EOS

response_json = { "jobs" => JSON.parse(groovy_script_output) }
response_json = response_json
response_json = groovy_script_output
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now returns a String instead of a Hash because JSON.parse was removed

@@ -702,17 +702,18 @@ def builder = new groovy.json.JsonBuilder(allInfo)
job_list_json()
EOS

response_json = { "jobs" => JSON.parse(groovy_script_output) }
response_json = response_json
response_json = groovy_script_output

jobs = Array.new
response_json["jobs"].each do |job|
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above the jobs hash key was removed so this no longer works.

if job.is_a?(Hash)
if job.key? :_class and job[:_class] !~ /com.cloudbees.hudson.plugins.folder.Folder/
if ignorecase
jobs << job[:name] if job[:name] =~ /#{filter}/i
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using symbols instead of strings now. When I used JSON.parse it returned strings so this did not work for me.

@dayer4b
Copy link

dayer4b commented May 23, 2017

@tmiller it looks like we need more tests if this is breaking something! I'll take another look soon

@dayer4b
Copy link

dayer4b commented Jul 11, 2017

@tmiller, I'm sorry, but I can't tell by your comments if this is breaking something for you or needs to be fixed. Can you be more specific about what functionality is broken?

@katelovescode
Copy link
Contributor

katelovescode commented Nov 27, 2017

@sahal @dayer4b - take a look at the change I made to the list method; the output of the Groovy script is not a hash with a jobs key, but an array of job hashes, which needs to be JSON.parsed to loop through it. Also calling the keys by symbol wasn't working, so I swapped it to strings. There's more work that needs to be done on this; many of the list_ methods rely on this and the nesting isn't working for all of them. list_all still only lists top-level jobs and top-level folders.

I was testing this locally with an instance of Jenkins running, the login_with_irb script, and @client.job.list("job_name"). I have CloudBees folders installed locally and I created jobs at the top level and one folder deep, but didn't get further than that.

With a search for a job named geordi, with one job named geordi at root, and one job named geordi inside a picard folder, the output of puts response_json at line 706 of job.rb is the following:

[{"_class":"hudson.model.FreeStyleProject","name":"geordi","url":"http://0.0.0.0:8080/job/geordi/"},{"_class":"hudson.model.FreeStyleProject","name":"kate","url":"http://0.0.0.0:8080/job/kate/"},{"_class":"com.cloudbees.hudson.plugins.folder.Folder","name":"picard","url":"http://0.0.0.0:8080/job/picard/"},{"_class":"hudson.model.FreeStyleProject","name":"picard/geordi","url":"http://0.0.0.0:8080/job/picard/job/geordi/"},{"_class":"hudson.model.FreeStyleProject","name":"picard/riker","url":"http://0.0.0.0:8080/job/picard/job/riker/"},{"_class":"hudson.model.FreeStyleProject","name":"whatever","url":"http://0.0.0.0:8080/job/whatever/"}]

Hope that helps!

@katelovescode
Copy link
Contributor

@sahal @dayer4b - this PR might help: #237

@katelovescode
Copy link
Contributor

#256 <-- my changes are in this PR. I'm still getting used to Github over Stash/Bitbucket

@snowe2010
Copy link

Hi, what is the status of this pr? Is anyone working it? We're looking at using this gem, but it's completely useless to us without this PR. Not a single job is outside of a folder for us.

@arangamani
Copy link
Owner

Hi @snowe2010, According to @katelovescode's comment above, this needs more work and I don't believe anybody is actively working on it. Feel free to take a stab at it if you're interested.

@snowe2010
Copy link

I'll pass it along to the team to let them know. Not sure if one of us will have time to take it though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants