# How to use embeddable-build-status-plugin to display code coverage

**URL:** <https://community.jenkins.io/t/how-to-use-embeddable-build-status-plugin-to-display-code-coverage/11463>\
**Category:** Ask a question\
**Tags:** question, code-coverage\
**Created:** [December 26, 2023, 7:06am UTC](https://community.jenkins.io/t/how-to-use-embeddable-build-status-plugin-to-display-code-coverage/11463 "2023-12-26T07:06:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonesbusy](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/jonesbusy/32/2643_2.png) [@jonesbusy](https://community.jenkins.io/u/jonesbusy)\
**Post date:** [December 26, 2023, 7:06am UTC](https://community.jenkins.io/t/how-to-use-embeddable-build-status-plugin-to-display-code-coverage/11463/1 "2023-12-26T07:06:28Z")

</div>

Hi,

I’m trying to display badges from `embeddable-build-status-plugin` but that display the code coverage (Like [codecov.io](http://codecov.io)). Assuming ‘coverage-plugin’ is also installed and correctly display coverage (column or graph). Typically I want to get a badge similar to the column definition

 ![coverage](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/7/7529b635490fdb661a4942c8d2e3e7e52ae47d2d.png)

Even after reading embeddable-build-status-plugin I don’t get exactly how we can extends the plugin to also display such badges (Perhaps we should implement a plugin implementing some extension point ?).

Thanks!

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [December 26, 2023, 1:46pm UTC](https://community.jenkins.io/t/how-to-use-embeddable-build-status-plugin-to-display-code-coverage/11463/2 "2023-12-26T13:46:27Z")

</div>

Thanks for your interest! The embeddable build status plugin documentation is weak or non-existent for this scenario. I’m not sure that it currently can handle the feature that you need.

There is an [example](https://plugins.jenkins.io/embeddable-build-status/#plugin-content-pipeline-dsl) that shows how to create an additional embeddable status, but even that example is missing a lot of description.

Let’s use this topic to better describe the creation of an additional embeddable status configuration and explore the techniques needed to describe it better, then the plugin documentation can be updated. If that helps with your scenario, that is great. If it doesn’t help with your scenario, then we will have at least explored a scenario for others.

If you are willing to adapt the Pipeline job definition rather than extend the plugin, you can define a new embeddable build status configuration in the Pipeline job.

Here is a Pipeline job that reports a fake coverage number based on the build number:

```groovy
pipeline {
    agent any
    stages {
        stage('Fake coverage') {
            steps {
                script {
                    int buildNumber = env.BUILD_ID as int
                    // rotate coveragePercent from 20% to 100%
                    coveragePercent = 20 * (1 + buildNumber % 5) 
                    // set coverageColor based on coveragePercent
                    if (coveragePercent > 30) {
                        coverageColor = "yellow"
                    }
                    if (coveragePercent > 50) {
                        coverageColor = "yellowgreen"
                    }
                    if (coveragePercent > 70) {
                        coverageColor = "green"
                    }
                    if (coveragePercent > 90) {
                        coverageColor = "brightgreen"
                    }
                    echo "Coverage is ${coveragePercent}%"
                    // Use embeddable build status badge to report coverage
                    coverageBadge = addEmbeddableBadgeConfiguration(id: "coverage", subject: "Coverage:")
                    coverageBadge.setStatus(coveragePercent + "%")
                    coverageBadge.setColor(coverageColor)
                    echo "Coverage badge URL is ${currentBuild.absoluteUrl}/badge/icon?config=coverage"
                    // Use groovy postbuild plugin to add a badge to the build history entry
                    textColor = "black"
                    border = coverageColor
                    borderColor = "transparent"
                    backgroundColor = coverageColor
                    manager.addShortText(coveragePercent + "%", textColor, backgroundColor, border, borderColor)
                }
            }
        }
    }
}

```

That job will report the added embeddable build status URL in the build log.

However, that technique requires that every Pipeline job must be modified to include that embeddable build status configuration.

---

<div class="post-metadata">

**Author:** ![jonesbusy](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/jonesbusy/32/2643_2.png) [@jonesbusy](https://community.jenkins.io/u/jonesbusy)\
**Post date:** [December 26, 2023, 3:52pm UTC](https://community.jenkins.io/t/how-to-use-embeddable-build-status-plugin-to-display-code-coverage/11463/3 "2023-12-26T15:52:41Z")

</div>

Thanks you! But I think I will go ahead with plugin code. I don’t want to implement this logic on every pipeline (even encapsulated inside a jenkins library). I have already hundreds of pipeline already using the `recordCoverage` step.

By reading the code I think I can implement the extension point `ParameterResolverExtensionPoint` [embeddable-build-status-plugin/src/main/java/org/jenkinsci/plugins/badge/extensionpoints/ParameterResolverExtensionPoint.java at 4a954796e45d9bba8602ff102565cad1668f65d5 · jenkinsci/embeddable-build-status-plugin · GitHub](https://github.com/jenkinsci/embeddable-build-status-plugin/blob/4a954796e45d9bba8602ff102565cad1668f65d5/src/main/java/org/jenkinsci/plugins/badge/extensionpoints/ParameterResolverExtensionPoint.java)

And resolve 2 new value (coveragePercentage and coverageColor) and could be resolved in URL like `<instanceUrl>/buildStatus/icon?job=job&status=${coveragePercentage}%25&color=${coverageColor}`

Could be a new plugin or an optional extension of `embeddable-build-status-plugin` activated when `coverage` plugin is also installed

---

<div class="post-metadata">

**Author:** ![jonesbusy](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/jonesbusy/32/2643_2.png) [@jonesbusy](https://community.jenkins.io/u/jonesbusy)\
**Post date:** [December 27, 2023, 9:58am UTC](https://community.jenkins.io/t/how-to-use-embeddable-build-status-plugin-to-display-code-coverage/11463/4 "2023-12-27T09:58:32Z")

</div>

I did a small plugin [GitHub - jonesbusy/coverage-badges-extension-plugin](https://github.com/jonesbusy/coverage-badges-extension-plugin)

See README to understand how it works. I will publish it in the next few days

I originally open a PR on the [Implement extension for code coverage badges by jonesbusy · Pull Request #280 · jenkinsci/embeddable-build-status-plugin · GitHub](https://github.com/jenkinsci/embeddable-build-status-plugin/pull/280) but I think it’s much better to create a new plugin to provide this extension. Specially if we need to provide more metrics.

Would be good it the plugin can also be installed on [ci.jenkins.io](http://ci.jenkins.io)
