← Back to team overview

python-jenkins-developers team mailing list archive

[Bug 1177831] Re: build_job with parameters fails since POST is not used.

 

I meet the same bug, my jenkins version is 1.580.  When build a job,
jenkins return 405.

I look up the REST API doc of jenkins, it need us to send 'POST' request to the url 'http://{host}/job/{job_name}/build' to trigger a job.
I tried below hack to work around this bug. Hoping this can do some help, if I can provide more information, please let me know. :)

diff --git a/jenkins/__init__.py b/jenkins/__init__.py
index 28fa192..a499277 100644
--- a/jenkins/__init__.py
+++ b/jenkins/__init__.py
@@ -477,8 +477,9 @@ class Jenkins(object):
         :param token: Jenkins API token
         '''
         self.assert_job_exists(name, 'no such job[%s]')
-        return self.jenkins_open(Request(
-            self.build_job_url(name, parameters, token)))
+        req = Request(self.build_job_url(name, parameters, token))
+        req.get_method = lambda: 'POST'
+        return self.jenkins_open(req)
 
     def stop_build(self, name, number):
         '''Stop a running Jenkins build.

-- 
You received this bug notification because you are a member of Python
Jenkins Developers, which is subscribed to Python Jenkins.
https://bugs.launchpad.net/bugs/1177831

Title:
  build_job with parameters fails since POST is not used.

Status in Python API for Jenkins:
  In Progress

Bug description:
  Jenkins requires a POST when a job URL has parameters.  Since python-
  jenkins does not pass urllib2.urlopen a data value a GET is used
  instead.  This results in a failure and the Jenkins error page is
  returned.

  To reproduce this bug:

  - Create a job with parameters.
  - In ipython:
  import jenkins
  j = jenkins.Jenkins(url)
  j.build_job(job_name, {param : value})

  This will fail.

To manage notifications about this bug go to:
https://bugs.launchpad.net/python-jenkins/+bug/1177831/+subscriptions


References