Reload Jenkins using API in bash script with curl

A crumb is a Jenkins token.

Create the following script jenkins_reload.sh:

#!/bin/bash
USER=admin
PASS=admin
crumb_id=$(curl -s --cookie-jar ./cookie 'http://localhost:8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)' -u $USER:$PASS)
curl -s -XPOST 'http://localhost:8080/reload' -u $USER:$PASS -H "$crumb_id" --cookie "./cookie"
Appending the cookie is needed because the following error occurs often:
Jenkins authorization issue — 403 No valid crumb was included in the request