pycontribs / jenkinsapi

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

job.invoke throws exception when building against CloudBees server #692

Closed mdear closed 5 years ago

mdear commented 5 years ago
ISSUE TYPE
Jenkinsapi VERSION

0.3.8

Jenkins VERSION

CloudBees Jenkins Enterprise 2.107.36.0.2-fixed

SUMMARY

Attempt to launch a build against a CloudBees team space URL failed with an exception from jenkinsapi.

EXPECTED RESULTS

I successfully used jenkinsapi to create a remote project (not shown), which resulted in a POST to the following URL: https://server.domain.com/jenkins/job/my_team/createItem

I expected the following snippet to work:

from jenkinsapi.jenkins import Jenkins
from jenkinsapi.utils.crumb_requester import CrumbRequester
base_url = "https://server.domain.com/jenkins/job/my_team"
username = "me"
password = "my_token"
crumb = CrumbRequester(baseurl=base_url, username=username, password=password)
jenkins = Jenkins(base_url, username=username, password=password)
job = jenkins['my_project']
job.invoke()
ACTUAL RESULTS

The call to job.invoke threw the following exception:

  File "/nobackup/mdear/jenkins-engine/lib/python3.5/site-packages/jenkinsapi/job.py", line 215, in invoke
    raise ValueError("Not a Queue URL: %s" % redirect_url)
ValueError: Not a Queue URL: https://engci-jenkins-sjc2.cisco.com/jenkins/queue/item/449093/

Commenting out this exception allowed the job.invoke call to pass as expected.

USEFUL INFORMATION

On CloudBees, the queue API base URL: https://server.domain.com/jenkins/queue/api/

is not available at the team level, whereas my CloudBees team REST API base URL is as follows: https://server.domain.com/jenkins/job/my_team/api/

As opposed to the typical queue API base URL for a standalone Jenkins server (not CloudBees): http://anotherserver.domain.com:8080/queue/api/

Ikuze commented 5 years ago

Hello,

I have no cloudbees jenkins to test it, but maybe if you use this value for jenkins url instead of the one you are using, it may work:

base_url = "https://engci-jenkins-sjc2.cisco.com/jenkins"

BR.

mdear commented 5 years ago

Thanks for the response. I must specify the team-extended URL in order to create projects and launch builds in my team space. Users can be allocated multiple team spaces, the base URL clarifies which one is used for project creation.

mdear commented 5 years ago

Is there another way this issue could be fixed or worked around ?

mdear commented 5 years ago

PR created and has been merged to master 9e0f8772fa2031a56063c77f14bdd8c92658f997