Add support for POST to build jobs

Bug #1461928 reported by Jason Antman
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Python Jenkins
New
Undecided
Unassigned

Bug Description

The current build_job() only supports simple key/value parameter pairs, such as those used by string parameters, not the dict-based parameters used by the parameterized build plugin (such as RunParameter, which specifies a reference to a previous run of a job).

When trying to build a job with the parameterized build plugin, build_job() fails. Hacking some debugging code (since there's no logging at all...) around the urllib calls shows that Jenkins is responding with a HTTP 405 (method not allowed) and a HTML body including this notice:

You must use POST method to trigger builds. (From scripts you may instead pass a per-project authentication token, or authenticate with your API token.) If you see this page, it may be because a plugin offered a GET link; file a bug report for that plugin

Revision history for this message
Jason Antman (jason-jasonantman) wrote :

Also, to be clear, this is with the latest 0.4.6 from pypi.

Revision history for this message
Khai Do (zaro0508) wrote :

Hmm. This should have been fixed in bug 1177831 Could you please provide a python-jenkins api call that will reproduce this issue? I'm guessing that it's the specific parameter you used.

Revision history for this message
Jason Antman (jason-jasonantman) wrote :

This was over a month ago... I can try to dig around and find it, but honestly I'm not even sure what I was trying to do when I encountered this problem...

Revision history for this message
Jason Antman (jason-jasonantman) wrote :

I can no longer reproduce this. My original issue had been about the Run Parameter type (hudson.model.RunParameterDefinition) but it appears that, while the Jenkins UI sends a POST with a dict for this parameter, it also accepts a simple string.

Revision history for this message
sandeep (srikhi) wrote :

In Jenkins, we can specify a parameter of type file. That basically allows the end user to launch the build with an input file.
Basically you can upload the file and store as file-X. Easy way to reproduce the issue is by creating a job that accepts only one parameter and of type File

This requires the parameter to passed as post body
Following code works by using jenkinsapi

    jenkin = Jenkins(jenkins_server_url, username=BOT_USER_ID,
                        password=API_TOKEN)

    data_file = open('./some-file.txt', 'r')
    JOB_URL = jenkins_server_url + 'job/' + JOBID
    new_job = Job(JOB_URL, JOBID, jenkin)
    new_job.invoke(securitytoken=API_TOKEN,
                                        block=True,
                                        files={'custom_build_bundle': data_file})

However, to pass this as build_job input doesn't seem to be possible.

Revision history for this message
sandeep (srikhi) wrote :

a POST with form entries is a fairly useful thing but uploading a file is another angle.
Another example where a post functionality is needed is "Update the description of a particular build"

Basically that requires a post to <Build-URL>/submitDescription

It appears the only way would be to create your own urllib2 request object and set its properties to POST and other contents and then feed to jenkins_open

It would be nice if there is an explicit support for Update / Post support in somewhat CRUD style.

Revision history for this message
Marcin Cieślak (saperski) wrote :

As of July 2020 POST is used in build_job. Can we close this?

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.