code-coverage-api-plugin icon indicating copy to clipboard operation
code-coverage-api-plugin copied to clipboard

Document result access from within pipeline

Open stefan6419846 opened this issue 2 years ago • 2 comments

Describe your use-case which is not covered by existing documentation.

I have to retrieve some coverage results from within a pipeline to do some custom handling with it. While this has been no real issue for the warnings-ng-plugin, it took me quite some time to figure out how to retrieve the desired values. Digging through the code, it seems like we need the following public calls:

import edu.hm.hafner.coverage.Metric
import io.jenkins.plugins.coverage.metrics.model.Baseline

def action = ...  // action of type io.jenkins.plugins.coverage.metrics.steps.CoverageBuildAction

def lineCoverage = action.getStatistics().getValue(Baseline.PROJECT, Metric.LINE)
def branchCoverage = action.getStatistics().getValue(Baseline.PROJECT, Metric.BRANCH)
def lineDelta = action.getStatistics().getValue(Baseline.PROJECT_DELTA, Metric.LINE)
def branchDelta = action.getStatistics().getValue(Baseline.PROJECT_DELTA, Metric.BRANCH)

Is this the desired public API? Or is there any "easier" alternative?

Nevertheless, it might make sense to actually document snippets like this to avoid having to dig through the whole code of both the code-coverage-api-plugin and coverage-model.

Reference any relevant documentation, other materials or issues/pull requests that can be used for inspiration.

No response

stefan6419846 avatar Sep 04 '23 14:09 stefan6419846

Actually there is no public API yet, since nobody asked for it up to now. There is a remote API which covers all basic use cases, but no step API. And there is no additional documentation yet, on how to access all those values.

So using the public methods is a good approach. If you need more methods or a simpler access please let me know or provide a PR.

uhafner avatar Sep 04 '23 19:09 uhafner

Thanks for the explanations. I agree that most users probably do not need to dig into these things and a documented external Groovy-based API has not the highest priority. Calling a JSON-based API might be feasible, but introduces the overhead for the HTTP requests and requires handling authentication etc.

As it turned out to take quite some time to understand how to get actual percentage strings and double values for the collected metrics (different class types for regular and delta values etc.), I would appreciate if at least some basic docs are provided. This might ensure that future changes at least take this into account as well.

stefan6419846 avatar Sep 05 '23 11:09 stefan6419846