Skip to main content
Background Image
  1. Posts/

How to Fix Shields.io Badges Not Displaying in Jenkins

·218 words·2 mins· ·
Xianpeng Shen
Author
Xianpeng Shen
Table of Contents

Issue
#

I have set up documentation publishing on Jenkins using the following Groovy code:

publishHTML([
    allowMissing: false,
    alwaysLinkToLastBuild: false,
    keepAll: false,
    reportDir: "docs/build/html/",
    reportFiles: 'index.html',
    reportName: "Documentation",
    useWrapperFileDirectly: true
])

However, some badges from Shields.io do not display properly within the published documentation.

Can not display badge on Jenkins

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(
  "hudson.model.DirectoryBrowserSupport.CSP",
  "default-src 'self'; img-src * data:;"
)

This allows images from any domain (img-src *), which includes Shields.io. If you want to restrict it more safely:

System.setProperty(
  "hudson.model.DirectoryBrowserSupport.CSP",
  "default-src 'self'; img-src 'self' https://img.shields.io data:;"
)

🟡 Note: This change is temporary (in-memory only). It will reset if Jenkins restarts.

✅ To Make It Permanent

  1. 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:;"
  1. Then restart Jenkins:
sudo systemctl restart jenkins

Results
#

The issue with Shields.io badges not displaying on Jenkins has now been resolved.

Can display badge on Jenkins


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.

Related

Jenkins Multibranch Pipeline
·405 words·2 mins
Discusses the use of Jenkins Multibranch Pipeline to manage multiple branches in a project, enabling parallel builds for pull requests and efficient code review processes.
Jenkins Linux agent configuration
·298 words·2 mins
Provides a step-by-step guide on how to configure a Jenkins Linux agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.
Jenkins Windows agent configuration
·544 words·3 mins
Provides a step-by-step guide on how to configure a Jenkins Windows agent, including setting up the Java runtime, creating the node, and troubleshooting common issues.
How to Change abortPrevious Value in Jenkins?
·418 words·2 mins
In Jenkins, the disableConcurrentBuilds option is used to manage concurrent builds. This article explains how to conditionally set the abortPrevious value based on the branch being built, allowing for more flexible build management.
What Optimizations I Made During the Jenkins Upgrade
·481 words·3 mins
This article discusses the optimizations made during the Jenkins upgrade, including using Docker Compose for deployment, refactoring the Jenkins Shared Library, introducing Windows Docker Containers, and more to enhance the efficiency and security of the CI/CD process.
How to make Jenkins pipeline not fail if a specific error occurs
·212 words·1 min
Introducing the catchError step in Jenkins pipeline to handle specific errors without failing the entire build, allowing for more flexible error management.