1

I am using Curl to make requests to the Jenkins API - which is being done over https. Jenkins is setup in IIS using a reverse proxy as advised by Jenkins. The Jenkins site has windows authentication. I need to pass a Crumb with my request - 403 error.

However, when I request for the Crumb, it states that I need to provide a Crumb? I need this to work via the command prompt/batch file.

Thanks

StackRice
  • 21
  • 1
  • 2

1 Answers1

2

To be able to do API calls to Jenkins, you need to generate a token for a given user in Jenkins. For example, let's do it with user Foo. You'll need to sign in with Foo user and then in the web UI: Foo (right upper corner) > Configure > API token > Add new token.

When you have your token saved somewhere, you can retrieve the breadcrumb with this command:

curl --user Foo:<token> 'https://www.mysuperduperjenkins.com/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'

What this is doing basically is fetching the XML from Jenkins that contains the breadcrumb and getting the specific element where the breadcrumb is. The result of the command should be something similar to:

Jenkins-Crumb:<someLongLongLongToken>

You can save the breadcrumb into a variable, for example name it breadcrumb and then:

curl -u 'Foo:<token>' -X POST --data '<parameters>' -H '$breadcrumb' www.mysuperduperjenkins.com

In this curl we're using the breadcrumb as a header, obtained in previous step. If the crumb is valid you should be able to perform the request without 403/401 errors.

Adam
  • 737
  • 1
  • 6
  • 20
  • Hi I have generated a token and using it with as the following --data "token=". This is because my organisation has setup Jenkins via IIS which has NTLM authentication. So I need to do : However, the problem is when I request for a crumb it gives me a 403 error no valid crumb. Why is it giving me that error when I want to get a crumb? Very strange... Any ideas? – StackRice Apr 05 '20 at 16:16
  • Oops, never had that setup... Maybe you can have a look here: https://stackoverflow.com/questions/17031965/curl-ntlm-proxy-authorization Maybe doing `curl --proxy-ntlm --proxy-user : --proxy : --user : 'https:///crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'` works? – Adam Apr 05 '20 at 16:59
  • But I won't get a 404 if I use HTTP... However I am required to use https – StackRice May 16 '20 at 15:30