I recently upgraded to Jenkins 2.192, and my applications started failing with the following error:
HTTP Error 403: No valid crumb was included in the request
Reason: No valid crumb was included in the request
I do not see the problem after downgrading to Jenkins 2.189. I do not see the issue with Jenkins 2.189, 2.190, 2.191. I hit the issue with Jenkins 2.192 (also seen with 2.196)
SOMETHING CHANGED BETWEEN 2.191 AND 2.192 , causing the failure I observed.
This script will return an error code if one of the curl command fails for any reason. Show activity on this post. So, not sure if that's a bug or not, but "No valid crumb was included in the request" could also mean you accidentally forgot the Authorization header.
GOTO: Jenkins > Manage Jenkins > Configure Global Security and enable Prevent Cross Site Request Forgery exploits . Select Default Crumb Issuer from Crumb Algorithm and save to apply changes and enable.
You now have to forward the session id (present in the cookie response that generated the crumb) every time you use that crumb. Example code, hopefully illustrates it:
async function duplicateProject() {
const jenkinsAxios = axios.create({
baseURL: 'http://jenkins_url',
auth: {
username: 'MY-USERNAME',
password: "MY-PASSWORD"
}
});
const {data: existingJobConfig} = await jenkinsAxios.get('/job/existingJob/config.xml');
const crumbIssuer = await jenkinsAxios.get('/crumbIssuer/api/json');
await jenkinsAxios.post(`/createItem?name=MY_NEW_PROJECT`, existingJobConfig, {
headers: {
'Content-Type': 'application/xml',
[crumbIssuer.data.crumbRequestField]: crumbIssuer.data.crumb,
Cookie: crumbIssuer.headers['set-cookie'][0] // <--- THIS IS KEY!!!!
}
}
);
}
A simple solution without need of making changes to source code (validated with Jenkins v2.222):
A drawback is that this solution makes us dependent on the Strict Crumb Issuer plugin and removes a security feature. But since our application requires many other plugins and only runs behind the firewall without Internet access, this is acceptable.
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