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?
How can we stop a scheduled job from being executed temporarily? Disable the job from the job details page to temporarily stop all scheduled executions & other factors/events from triggering the job and enable it back to resume the job schedules/triggers.
Disables the job, so that no new builds will be executed until the project is re-enabled.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With