Unable to trigger Jenkins job using API Token command-line curl

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Unable to trigger Jenkins job using API Token command-line curl

Mohtashim S

My requirement is to trigger(build) a jenkins job using command-line which I will invoke using ansible.

I'm following the instructions on this stackoverflow link.

I followed the below steps but Unfortunately the build does not get triggered.

Step 1: I logged in Jenkins portal https://myjenkins.com:9043 using my user id user114 which is also the Jenkins administrator.

I then created API-token for my user id which is 118f32aa48601c136d29y11f3dd0e107f5.

Step 2: I then selected Trigger Build Remotely option for job5 and gave the token name as 118f32aa48601c136d29y11f3dd0e107f5

Step 3: I then created Jenkins-Crumb using the below command:

curl -s -k 'https://user114:[hidden email]:9043/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)' Jenkins-Crumb:5196c183ad95cf3c0482873e34236f3b78ab628ecba968086cd19s7430016a4e

Then i tried the below commands with the intention of triggering the build for job5 but none of them triggered my Jenkins build.

Attemp 1:

$ curl -I -k -X POST https://user114:[hidden email]:9043/job/job5/build -H "Jenkins-Crumb:5196c183ad95cf3c0482873e34236f3b78ab628ecba968086cd19s7430016a4e" HTTP/1.1 400 Bad Request X-Content-Type-Options: nosniff Cache-Control: must-revalidate,no-cache,no-store Content-Type: text/html;charset=iso-8859-1 Content-Length: 481 Server: Jetty(NOTHING)

Attempt 2:

$ curl -k -X POST https://user114:[hidden email]:9043/job/job5/build -H "Jenkins-Crumb:5196c183ad95cf3c0482873e34236f3b78ab628ecba968086cd19s7430016a4e" <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 400 Nothing is submitted</title> </head> <body><h2>HTTP ERROR 400 Nothing is submitted</h2> <table> <tr><th>URI:</th><td>/job/job5/build</td></tr> <tr><th>STATUS:</th><td>400</td></tr> <tr><th>MESSAGE:</th><td>Nothing is submitted</td></tr> <tr><th>SERVLET:</th><td>Stapler</td></tr> </table> <hr><a href="http://eclipse.org/jetty">Powered by Jetty:// NOTHING</a><hr/> </body>

Attempt 3:

$ curl -k -X POST https://user114:[hidden email]:9043/job/job5/build?token=118f32aa48601c136d29y11f3dd0e107f5 -H "Jenkins-Crumb:5196c183ad95cf3c0482873e34236f3b78ab628ecba968086cd19s7430016a4e" <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 This page expects a form submission</h2> <table> <tr><th>URI:</th><td>/job/job5/build</td></tr> <tr><th>STATUS:</th><td>400</td></tr> <tr><th>MESSAGE:</th><td>This page expects a form submission</td></tr> <tr><th>SERVLET:</th><td>Stapler</td></tr> </table> <hr><a href="http://eclipse.org/jetty">Powered by Jetty:// NOTHING</a><hr/> </body> </html>

Further, I also intend to pass parameters to this jenkins job which i dont know how-to.

Can you please suggest ?

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/f901fe2b-a07c-408b-ab3f-acbfa822d8f4n%40googlegroups.com.