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

Listing Jenkins Jobs (within a folder) #79

Closed
choweiyuan opened this issue Jan 17, 2020 · 6 comments
Closed

Listing Jenkins Jobs (within a folder) #79

choweiyuan opened this issue Jan 17, 2020 · 6 comments
Assignees
Milestone

Comments

@choweiyuan
Copy link
Contributor

Expected Behavior

I'd like to use an API to list me jobs that are available within a folder (or root folder).

Current Behavior

I can't see any API within Jenkins-rest that supports this behaviour

Context

The use case is to allow user to select job based on the list of available jobs (whether it's inside a folder or not), rather than knowing the job name beforehand.

Sample API URL:
{jenkins-url}/api/json?tree=jobs[name]&pretty=true - will list you all jobs name on root folder
{jenkins-url}/job/{foldername}/api/json?tree=jobs[name]&pretty=true - will list you all jobs name within {foldername}

@cdancy
Copy link
Owner

cdancy commented Jan 17, 2020

@choweiyuan did you want to send in a PR for this? In the past I've purposefully shied away from doing this as the API itself returns raw json which in itself is extremely complicated instead of a more targeted API with very specific endpoints. However we can give something a go and try to just target this very specific use-case if you're willing to put something together.

@choweiyuan
Copy link
Contributor Author

I see, thanks for your explanation. I'll give it a go

@blajoie55
Copy link

+1 for this feature. My company is switching from Bamboo to Jenkins. We have a handful of java and groovy apps that rely on hitting REST api to get list of pipeline jobs, their current latest build status for each branch of the pipeline, etc. When researching how to use Jenkins REST api I found this github project, but unfortunately it's missing some very key features for us, such as given a folder endpoint/URL, return the list of jobs. E.g. in Postman can hit the Jenkins REST api with a URL like so: https://myJenkinsHost.com/job/folder1/job/folder2/job/myPipeline/api/json?pretty=true
That will return information about that jenkins pipeline including a list of jobs. I tried using the jenkins-rest project's JobApi jobInfo with the above URL/endpoint, but it doesn't support what we need. Hopefully this feature will be available soon!

@cdancy cdancy added this to the v0.0.23 milestone Jan 27, 2020
@cdancy
Copy link
Owner

cdancy commented Jan 27, 2020

@choweiyuan @blajoie55 v0.0.23 has been released with this change. Please kick the tires and let me know how things go.

And special thanks to @choweiyuan for knocking this out!

@cdancy cdancy closed this as completed Jan 27, 2020
@l3ender
Copy link

l3ender commented May 18, 2020

Thanks for this addition!

Just a note for anyone else who is looking. You can list all jobs by passing an empty String to the new method:

JobList jobList = jobs.jobList("");

Future enhancement could be to have the input for jobList method to be optional and to default to empty string if null input.

@cdancy
Copy link
Owner

cdancy commented May 18, 2020

@l3ender feel free to send in a PR with the proposed change/fix.

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

No branches or pull requests

5 participants