Issue
I have set up documentation publishing on Jenkins using the following Groovy code:
publishHTML([ |
However, some badges from Shields.io do not display properly within the published documentation.
How to fix it
✅ Working Script to Update Jenkins CSP in Script Console
Here’s the correct and minimal Groovy script you should run in Manage Jenkins → Script Console:
System.setProperty( |
This allows images from any domain (img-src *), which includes Shields.io. If you want to restrict it more safely:
System.setProperty( |
🟡 Note: This change is temporary (in-memory only). It will reset if Jenkins restarts.
✅ To Make It Permanent
- Modify Jenkins startup arguments (depends on how you run Jenkins):
If using /etc/default/jenkins
(Debian/Ubuntu):
JENKINS_JAVA_OPTIONS="-Dhudson.model.DirectoryBrowserSupport.CSP=\"default-src 'self'; img-src 'self' https://img.shields.io data:;\"" |
If using systemd service unit (CentOS/Red Hat-based or modern setups):
Edit or override your jenkins.service file:
Environment="JAVA_OPTS=-Dhudson.model.DirectoryBrowserSupport.CSP=default-src 'self'; img-src 'self' https://img.shields.io data:;" |
- Then restart Jenkins:
sudo systemctl restart jenkins |
Results
The issue with Shields.io badges not displaying on Jenkins has now been resolved.
Please credit the author and source when reposing this article. Commercial use is not permitted. You’re welcome to subscribe to my blog via RSS.