Closed medianick closed 1 year ago
You can use
def action = build.getAction(io.jenkins.plugins.coverage.metrics.steps.CoverageBuildAction.class)
to get the action from a build.
Note, that Jenkins security system does not provide access to internal objects. So in order to use the action we need to whitelist the required methods.
Which results do you need? We already have a remote API that provides a lot of those results. Is there missing something? Maybe it would be simpler to expose those results as tokens, see #178.
What I was previously relying on was being able to fetch the CoverageResult
object, whose getCoverage
method I could then call to get the different kinds of coverage (e.g., CoverageElement.LINE
) as int
s or float
s. I have tooling that takes this and does things like renders build badges with the numbers.
And yes, if I were doing this directly within Jenkinsfile
s it would require more whitelisting but this is being done through a shared library, so I can just call, e.g., def coverage = getCoverage()
in my Jenkinsfile
to get the object in question.
It seems like the change here with recordCoverage
is a different action class -- CoverageBuildAction
rather than CoverageAction
(as with publishCoverage
) -- so I'll have to rework the logic to see if I can still extract compatible structure from it.
I had noted the token macro issue (#178) and knew of the API possibility but did not want to deal with the additional overhead of authenticating; the internal objects are accessible directly from my pipeline builds so were the most convenient (but at risk of changes, as this shows).
I've managed to resolve this for the statistics I previously retrieved from CoverageAction
to obtain them from CoverageBuildAction
(and CoverageStatistics
, etc.) instead. I'll close this ticket and await #178 as a more supported way to obtain this data inside a pipeline. Thanks for the assistance!
Jenkins and plugins versions report
Environment
```text Paste the output here ```What Operating System are you using (both controller, and any agents involved in the problem)?
Amazon Linux 2 for controller and agents
Reproduction steps
Previously with
publishCoverage
, I was able to callcurrentBuild.rawBuild.getAction(CoverageAction.class)
to return a CoverageAction object, from which I could access coverage details via itsgetResult()
method (which then returned a CoverageResult object with agetCoverage(CoverageElement)
method, etc.). My mechanism is very similar to the implementation in https://github.com/rguenthe/pipeline-coverage-results-plugin/blob/master/src/main/java/io/jenkins/plugins/pipelinecoverageresults/GetCoverageStep.java#L104, but with a slightly different way to access the CoverageAction object. In my case, this is run as a Groovy file via a Shared Library method.Is there a different syntax to use that would allow this CoverageAction object to be retrieved after
recordCoverage
has been called, as previously worked withpublishCoverage
?Expected Results
Expected to retrieve the CoverageAction object the same way as with
publishCoverage
Actual Results
Got a null object instead
Anything else?
No response