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

18 views
Skip to first unread message

Mohtashim S

unread,
Sep 17, 2020, 6:11:09 PM9/17/20
to Jenkins Users

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:118f32aa48601c136...@myjenkins.com: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:118f32aa48601c136...@myjenkins.com: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:118f32aa48601c136...@myjenkins.com: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:118f32aa48601c136...@myjenkins.com: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 ?

Reply all
Reply to author
Forward
0 new messages