Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Support for jobs in folders #5

Open
sschwarzer opened this issue Oct 17, 2014 · 3 comments
Open

Support for jobs in folders #5

sschwarzer opened this issue Oct 17, 2014 · 3 comments

Comments

@sschwarzer
Copy link

Hello, thanks for your library. :-)

This issue is for jenkins-webapi version 0.3.0.

When I tried to create a new job inside a folder (created with the Cloudbees Folder Plugin, https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Folders+Plugin ) with

job2 = server.job_create("TestFolder/TestJob2", job_config)

(where server is a Jenkins instance and job.config is the XML configuration of an already existing job) I got the following traceback:

Traceback (most recent call last):
  File "D2SG/jenkins/jenkins_webapi_test.py", line 27, in <module>
    main()
  File "D2SG/jenkins/jenkins_webapi_test.py", line 23, in main
    job2 = server.job_create("TestFolder/TestJob2", job_config)
  File "/home/schwste/lib/python/jenkins.py", line 436, in job_create
    return Job.create(name, config, self.server)
  File "/home/schwste/lib/python/jenkins.py", line 158, in create
    raise JenkinsError('create "%s" failed' % name)
jenkins.JenkinsError: create "TestFolder/TestJob2" failed

It seems that the library tries to use /createItem?name=TestFolder/TestJob2 as the URL path instead of /job/TestFolder?createItem?name=TestJob2.

Stefan

@sschwarzer
Copy link
Author

By the way, adding support for folders (to create the folders for the jobs to begin with) seems to be trivial. If you create a "job", but use the config.xml of an existing folder, the REST API creates a new folder. I assume you'll need the folders plugin (see above) to be installed.

@gvalkov
Copy link
Owner

gvalkov commented Oct 28, 2014

Hello, and sorry for the late reply.

The Folder plugin actually breaks a lot of things. For example:

>>> j.jobs
[Job('RealJob'), Job('FolderName')]
>>>  j.jobs[0].buildnumbers
[1, 2, 3]
>>> j.jobs[1].buildnumbers
KeyError: 'builds'  # because it's not really a Job

I'm not too sure about adding special handling for plugins to jenkins-webapi - I'll give it some more though. Please consider the following workaround in the meantime:

>>> j = Jenkins('http://jenkins.sschwarzer.com/FolderName')  
>>> j.jobs  # all jobs in this folder
>>> j.create_job('new')  # creates a job in the folder

@KimonHoffmann
Copy link

Well I'm a bit late to the party, but I want to note that the suggested workaround does not work for Jenkins instances that are configured with CSRF protection enabled, because unfortunately it is not possible to request the crumb on the folder level.

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

No branches or pull requests

3 participants