curl 訪問最新版jenkins api 報 Error 403 No valid crumb was included in the request 解決辦法
Using cURL
The following example retrieves a crumb and uses it to build a job called someJob
.html
Before 2.176.2, no session required:web
# Replace with your Jenkins URL and admin credentials SERVER="http://localhost:8080" CRUMB=$(curl -u "admin:admin" "$SERVER"/crumbIssuer/api/xml?xpath=concat\(//crumbRequestField,%22:%22,//crumb\)) curl -X POST -u "admin:admin" -H "$CRUMB" "$SERVER"/job/someJob/build
After 2.176.2, session is required:api
# Replace with your Jenkins URL and admin credentials SERVER="http://localhost:8080" # File where web session cookie is saved COOKIEJAR="$(mktemp)" CRUMB=$(curl -u "admin:admin" --cookie-jar "$COOKIEJAR" "$SERVER/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,%22:%22,//crumb)") curl -X POST -u "admin:admin" --cookie "$COOKIEJAR" -H "$CRUMB" "$SERVER"/job/someJob/build
Parameters:cookie
-u "<USERNAME>:<PASSWORD_OR_API_TOKEN>"
-H "<ISSUED_CRUMB_FOR_USER>"
Debugging Issues
I’m seeing the following response:session
<html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 400 Nothing is submitted</title> </head> <body><h2>HTTP ERROR 400 Nothing is submitted</h2> <table> <tr><th>URI:</th><td>/job/CICD_booking_Job/build</td></tr> <tr><th>STATUS:</th><td>400</td></tr> <tr><th>MESSAGE:</th><td>Nothing is submitted</td></tr> <tr><th>SERVLET:</th><td>Stapler</td></tr> </table> <hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.27.v20200227</a><hr/> </body> </html>