3

I've been trying to trigger a build via the Jenkins API so far with no success. I configured a job on 'Trigger builds remotely' and set a token, 'abc'.

Then in postman I did a post to:

$jenkinsurl:$port/job/$jobname/build?token=abc

And the response is:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Error 403 No valid crumb was included in the request</title>
</head>
<body>
    <h2>HTTP ERROR 403</h2>
    <p>Problem accessing /job/DCD%20Specifications/build. Reason:

        <pre>    No valid crumb was included in the request</pre>
    </p>
    <hr>
    <i>
        <small>Powered by Jetty://</small>
    </i>
    <hr/>
</body>

I also tried to use basic authentication with a valid username and password, but to no avail.

I can use gets to retrieve whatever information I want from the Jenkins API just fine; it's only this post that gives me this problem.

I had Jenkins 2.7 and updated to 2.19.4 and both versions give me this problem. What am I doing wrong here?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
BRNTZN
  • 564
  • 1
  • 7
  • 21

2 Answers2

4

Pass in POST headers, "Jenkins-Crumb:5740ac1b614ca59f5dd5ef151b2895b3".

Your Crumb can be obtained from the URL http://jenkins:8080/crumbIssuer/api/xml

In the POST body, use the appropriate Jenkins XML API request.

Here is my Postman images with parameters:

Postman Jenkins Jenkins-Crumb

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Max
  • 4,292
  • 1
  • 20
  • 14
3

This worked for me:

Obtain crumb

$ wget -q --auth-no-challenge --user yourUserName --password yourPassword--output-document - 'http://myJenkins:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'

Now run the Jenkins job

$ curl -I -X POST http://yourUserName:yourPassword@myJenkins:8080/job/JOBName/build -H "Jenkins-Crumb:44e7038af70da95a47403c3bed5q10f8"

HTTP/1.1 201 Created 
Date: Fri, 28 July 2017 09:15:45 GMT
X-Content-Type-Options: nosniff 
Location: http://myJenkins:8080/queue/item/17/
Content-Length: 0
Community
  • 1
  • 1
Prateek Kapoor
  • 947
  • 9
  • 18
  • 1
    Yes, the user/password thing is also needed for running the Jenkins job. – Peter Mortensen Jul 18 '18 at 13:31
  • Using Wget for running the Jenkins job, I found "`=`" was required for specifying the value `Jenkins-Crumb` (not "`:`"); the parameters to Wget were `--auth-no-challenge --user SomeUserName --password $MYPASSWORD --post-data="Jenkins-Crumb=4c69243fb6d96efd69..."` – Peter Mortensen Jul 18 '18 at 13:33