Reputation: 1149
I want to disable a Jenkins job by sending a post curl request to Jenkins.
I've tried doing that using:
curl -X POST http://<server>:8080/<jobname>/disable
curl -X POST http://<server>:8080/<jobname>/disable?token=<token>
curl -u <username>:<token> POST http://<server>:8080/<jobname>/disable
but failed every time. The error i am getting is:
403 no valid crumb was included in the request
Is there a good curl based solution to this problem?
Upvotes: 20
Views: 25718
Reputation: 166843
No valid crumb means your Jenkins installation has a security option enabled which prevent requests send in a standard way to avoid one-click attacks. You can't use Jenkins CLI either, because it doesn't work yet.
Here are the steps using curl
(replace localhost
with your Jenkins address):
/user/USER/configure
).Get your crumb:
CRUMB=$(curl -s 'http://USER:TOKEN@localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)')
Now you can disable the job by sending the crumb in the headers:
curl -X POST -H "$CRUMB" http://USER:TOKEN@localhost:8080/<jobname>/disable
If the above won't work for some reason, you may try to use -u USER:TOKEN
instead.
Upvotes: 21
Reputation: 1780
I found the first part of kenorb's solution worked for me, i.e. getting the crumb, but for the second part, curl did not like that syntax, it said:
curl: (6) Couldn't resolve host 'http:'
So I had to use the following syntax which worked:
curl -H $CRUMB http://localhost:8080/<jobname>/disable -u USER:TOKEN
Upvotes: 3
Reputation: 57
setup jenkins's "global security settings": Uncheck "Prevent Cross Site Request Forgery exploits"
Upvotes: 4
Reputation: 662
The below is working for me
curl -X POST http://<servername>/job/jobname/disable
Make sure the user access to do that.
Upvotes: 1
Reputation: 15982
The crumb error indicates you are using CSRF Protection. You need to include a proper crumb header in your request. The crumb can be obtained from the Jenkins API as described on the Jenkins wiki page linked above. The answer for "Trigger parameterized build with curl and crumb" shows the syntax to adding the crumb header in the curl request.
Upvotes: 11