pycontribs / jenkinsapi

A Python API for accessing resources and configuring Hudson & Jenkins continuous-integration servers
http://pypi.python.org/pypi/jenkinsapi
MIT License
857 stars 485 forks source link

Add support for folders #791

Open sodul opened 4 years ago

sodul commented 4 years ago
ISSUE TYPE
Jenkinsapi 0.3.11
Jenkins 2.235.5
cloudbees-folder@6.9
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
lechat commented 4 years ago

I am happy to accept pull request for this.

BramDriesen commented 3 years ago

Bummer, we're also using folders, meaning I can't fetch the job status of the actual jobs inside the folder 😢

sodul commented 3 years ago

@BramDriesen try my workaround, it works well enough for us.

BramDriesen commented 3 years ago

@sodul Yes, your workaround works fine :) but an native supported function would have been better ;)

sodul commented 3 years ago

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:

lechat commented 3 years ago

Nevertheless nobody submitted pull request to add support for this. Why not?

sodul commented 3 years ago

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?

joelee2012 commented 3 years ago

@sodul maybe you can try https://api4jenkins.readthedocs.io/en/latest/user/example.html#folder

sodul commented 3 years ago

After submitting 2 PRs 3 weeks ago with no response I am switching to the python-jenkins library instead.

BramDriesen commented 3 years ago

@sodul Care to send a link? 😄

sodul commented 3 years ago

@BramDriesen: https://pypi.org/project/python-jenkins/