jenkinsapi
jenkinsapi copied to clipboard
Add support for folders
ISSUE TYPE
- Feature Idea
Jenkinsapi 0.3.11
Jenkins 2.235.5
[email protected]
SUMMARY
When creating a folder with create_job()
it works fine, but then since this is not actually a job an exception is raised when jenkinsapi tries to get the job object back. It would need to be able to make the distinction between folders and jobs.
Next issue is that to create a folder, or a job that is inside the folder the API url should be changed.
For example for job foo/bar
the url that jenkinsapi tries to use is http://host/createItem?name=foo%2Fbar
but the url should be http://host/job/foo/createItem?name=bar
.
If the job is foo/bar/baz
then the url would be http://host/job/foo/job/bar/createItem?name=baz
.
EXPECTED RESULTS
The folders and jobs in subfolders should be created without a glitch.
ACTUAL RESULTS
We get a JenkinsAPIException: Operation failed.
error, and the job is not created.
USEFUL INFORMATION
To reproduce install the Cloudbees Folder plugin: https://plugins.jenkins.io/cloudbees-folder/
Create folders and jobs under the folders.
This is a workaround to massage the baseurl:
if '/' in name:
folder, name = name.rsplit('/', 1)
server = copy.deepcopy(server)
folder_path = '/'.join([f'job/{x}' for x in folder.split('/')])
server.baseurl = server.baseurl + '/' + folder_path
I am happy to accept pull request for this.
Bummer, we're also using folders, meaning I can't fetch the job status of the actual jobs inside the folder 😢
@BramDriesen try my workaround, it works well enough for us.
@sodul Yes, your workaround works fine :) but an native supported function would have been better ;)
I took a look at the code and it would take a bit of effort to add full support. Most importantly there are several design decisions that would need to be addressed:
- I believe '/' is not going to be allowed in names, but we should make sure that nobody would have such a job.
- The 'jobs' are currently tracked as a flat dictionary, if we want to add them, it means that we either need to recursively fill the structure proactively, or maybe have folders as a separate group of items. The users will have to perform the recursion. I favor this approach as it is closer to the API and would scale better, as well as make it easier to scope changes to a specific folder.
Nevertheless nobody submitted pull request to add support for this. Why not?
I'm looking into it, but no promises. I have not worked with python 2 in several years so I'll have to get used to make things backward compatible if I do implement something.
Would you know the plans to deprecate 2.7 support so the codebase can be cleaned up?
@sodul maybe you can try https://api4jenkins.readthedocs.io/en/latest/user/example.html#folder
After submitting 2 PRs 3 weeks ago with no response I am switching to the python-jenkins library instead.
@sodul Care to send a link? 😄
@BramDriesen: https://pypi.org/project/python-jenkins/