createItem (with view) via REST API fails in Jenkins 2.x

318 views
Skip to first unread message

Alex Ellis

unread,
Feb 20, 2017, 9:34:04 AM2/20/17
to Jenkins Users
Hi,

I've been creating items (posting jobs) to a view in Jenkins 1.x with security turned off for development only. I've matched the same configuration with a Jenkins 2.3 host. I'm getting an odd failure with only the higher version of Jenkins.

I'm looking for help/suggestions to get past this issue and be able to run my automation code against Jenkins 2.x.

Thanks,

Alex Ellis

* Jenkins 1.x accepts post to both of these endpoints:

/view/<view_name>/createItem?name=
/createItem?name=

* Jenkins 2.x gives an error about needing a form post when I try to create a job inside a view, but when I create a job at the root level it's fine:

/view/<view_name>/createItem?name= (fails)

/createItem?name= (ok)

Error:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 400 This page expects a form submission</title>
</head>
<body><h2>HTTP ERROR 400</h2>
<p>Problem accessing /view/viewnamehere/createItem. Reason:
<pre> This page expects a form submission</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>
</body>
</html>

I'm using a Golang HTTP request from the standard library to perform the post:

response, err := http.Post(urlTotal, "application/xml", reader)
if err != nil {
    log.Println(err)
}
out, _ := ioutil.ReadAll(response.Body)
fmt.Println(string(out))
fmt.Printf("[createJob] Status code: %d\n", response.StatusCode)
defer response.Body.Close()



Daniel Beck

unread,
Feb 20, 2017, 11:39:07 AM2/20/17
to jenkins...@googlegroups.com

> On 20.02.2017, at 15:34, Alex Ellis <alexe...@gmail.com> wrote:
>
> Jenkins 1.x … 2.x.

Are you saying it worked in Jenkins 1.656, the last release of the 1.x line, but does not work in Jenkins 2.0, and continues to not work in Jenkins 2.47?

If not, please specify the exact versions.


Alex Ellis

unread,
Feb 20, 2017, 11:42:53 AM2/20/17
to jenkins...@googlegroups.com
It works in 1.656 but not in Docker image named jenkins:latest which uses exact version: Jenkins ver. 2.32.2



--
You received this message because you are subscribed to a topic in the Google Groups "Jenkins Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-users/t-vkqn4wbDs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9FD93A5D-4240-4928-A3C4-CF88DAA3DB4B%40beckweb.net.
For more options, visit https://groups.google.com/d/optout.



--
Regards,

Alex Ellis

Alex Ellis

unread,
Feb 20, 2017, 12:18:43 PM2/20/17
to jenkins...@googlegroups.com
Same error with jenkinsci/jenkins:latest which is version - Jenkins ver. 2.46

In effect I need to create a job within a view, or create a job and immediately move it into a view through the HTTP API.

Alex
--
Regards,

Alex Ellis

Baptiste Mathus

unread,
Feb 21, 2017, 5:25:53 AM2/21/17
to jenkins...@googlegroups.com
I think it would be very helpful if you can narrow down the exact Jenkins version it started failing with.

Using jenkinsci/jenkins you will also have weeklies on the docker hub (only LTS are published on the official image, so there are pretty big version jumps there).

Thanks Alex !


You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CAP%2BZTNT3UZXjTxmoFsDRGExNSNFO%3D6Yxa9Wez%3Dp0msbAzLa4zQ%40mail.gmail.com.

Alex Ellis

unread,
Feb 21, 2017, 5:59:12 AM2/21/17
to jenkins...@googlegroups.com
I do not know which version introduced breakage - I moved straight from 1.6 to 2.3/2.4. And the error is easily reproducible. To get the exact version for you will involve downloading every iteration between 1.6 and 2.3 and installing/testing one-by-one - are there any Java developers in the team on the distribution list who can look at the code diff for the view/createItem endpoint?

All I need is either the endpoint to work or an alternate method via the REST API of adding an existing job to a view.



For more options, visit https://groups.google.com/d/optout.



--
Regards,

Alex Ellis

Alex Ellis

unread,
Feb 21, 2017, 6:06:47 AM2/21/17
to jenkins...@googlegroups.com

Daniel Beck

unread,
Feb 21, 2017, 6:27:00 AM2/21/17
to jenkins...@googlegroups.com

> On 21.02.2017, at 11:58, Alex Ellis <alexe...@gmail.com> wrote:
>
> To get the exact version for you will involve downloading every iteration between 1.6 and 2.3 and installing/testing one-by-one

Not quite. A binary search takes at most log2(n) iterations. Also, please note that "1.6" isn't a version of Jenkins (but if it was, it would have been released around 10 years ago), while 2.3 is almost a year old. Those next digits are very important if you're discussing regressions.

> an alternate method via the REST API of adding an existing job to a view.

As documented on /view/whatever/api:

> Add Job to View
>
> To add a job to this view, send a POST request to this URL […/view/…/addJobToView] with query parameter name=JOBNAME. You'll get 200 status code if the job was successfully added to this view, or 4xx/5xx code if it fails.
Reply all
Reply to author
Forward
0 new messages