Error 405 - Method not allowed while triggering job using API call

Hi team!
Could you advise how the following can be troubleshooted:
curl -I -u myuser:MY USER TOCKEN ADDED HERE “http://jenkins-lab.com/job/test/build?token=JOB TOKEN ADDED HERE”

The output message I get is:
HTTP/1.1 405 Method Not Allowed
Date: Tue, 06 Jun 2023 09:48:50 GMT
Server: Jetty(9.4.43.v20210629)
X-Content-Type-Options: nosniff
Content-Type: text/html;charset=utf-8
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Cache-Control: no-cache,no-store,must-revalidate
X-Hudson-Theme: default
Referrer-Policy: same-origin
Cross-Origin-Opener-Policy: same-origin
X-Hudson: 1.395
X-Jenkins: 2.332.1
X-Jenkins-Session: 819be175
X-Frame-Options: sameorigin
X-Instance-Identity: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzUDrd2+8cn9YhLKSxM8uMXSgR0xetQ/sSwpAtAicsFb8yuiErH0kpdkGxIo1tj7CR+bXCVcJIWWKq0m9r4YofOLa/6cl2R7E3Ae+4vPK9XlkvV54W4bRnF/otaO/9SfO3ooU3OISaJMxnW7YVwQ11ZgOyshkHLblwKVhjc3xNsNhSlf6mtSCV7G+pKodw1O0vEyp+zkubgHxIgPWfO+gqbuol9glh18krDR1H2D1AP9izhNe0+lXoezEtp+LxdcVL1/6FPyG7lgz2IycoJuJV5g7/T9TcK5kDTGa+9VRSuaMQbZ3FQ+1cSnAEfQwkNoWawpwlbDNE1nruP4Nz0ITEQIDAQAB
Transfer-Encoding: chunked
Set-Cookie: JSESSIONID.28652b51=node06mhsaov3kwhzhsoe7tigr7jo3.node0; Path=/; HttpOnly

It happens so far only on one server that is version 2.332.1, no issue found on other servers that are running on versions 2.319.3 or 2.332.3.
Is there way to get more detailed information what could cause the issue (I suspect it could be a plugin).

Thank you in advance!

Kind regards,

Nik

Seems you’re doing a GET or HEAD request. That doesn’t work. You have to do a post request to trigger a build:
curl -X POST -u myuser:MY USER TOCKEN ADDED HERE “http://jenkins-lab.com/job/test/build?token=JOB TOKEN ADDED HERE”

Thank you for the reply but with the upper options it works for the rest of the servers just fine:
Once the job is executed on other server we get this output:
HTTP/1.1 201 Created
Date: Tue, 06 Jun 2023 13:29:55 GMT
Server: Jetty(9.4.43.v20210629)
X-Content-Type-Options: nosniff
Location: HIDDEN

When executing the suggested by you command on the working servers it triggers silently the build (no output but build is started).
But on the same server where we hit the problem we get the following using the -X POST curl command:

Error 400 This page expects a form submission

HTTP ERROR 400 This page expects a form submission

URI: /job/test/build
STATUS: 400
MESSAGE: This page expects a form submission
SERVLET: Stapler

Powered by Jetty:// 9.4.43.v20210629

So I suppose there is something in the configuration in the Jenkins master itself that causes the issue, but not sure how to get additional information what could be the problem.

Does the job have parameters? If yes you need to post to ...test/buildWithParameters

2 Likes

You are time and life savior!! Thank you very much. Indeed the job was parametrized and using it with your suggestion works like a charm!