0

I'm new to this and not sure if I'm doing this right.

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:118f32aa48601c136d29y11f3dd0e107f5@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:118f32aa48601c136d29y11f3dd0e107f5@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:118f32aa48601c136d29y11f3dd0e107f5@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:118f32aa48601c136d29y11f3dd0e107f5@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 ?

Ashar
  • 2,942
  • 10
  • 58
  • 122

1 Answers1

0

I started using the Generic Webhook Plugin for this. It takes away a lot of the hassle and allows you to parse any JSON/XML payload as you please.

smelm
  • 1,253
  • 7
  • 14