jenkinsci / code-coverage-api-plugin

Deprecated Jenkins Code Coverage Plugin
https://plugins.jenkins.io/code-coverage-api/
MIT License
111 stars 77 forks source link

Remote API not working #718

Closed JulienElkaim closed 1 year ago

JulienElkaim commented 1 year ago

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

I am using Jenkins 2.401.1, Code Coverage API 4.7.0

I use the plugin by doing a stage like this:

stage('Coverage Report'){
            steps{
                recordCoverage(tools: [[parser: 'JACOCO']],
                        id: 'jacoco', name: 'JaCoCo Coverage',
                        sourceCodeRetention: 'EVERY_BUILD',
                        qualityGates: [
                                [threshold: 60.0, metric: 'LINE', baseline: 'PROJECT', unstable: true],
                                [threshold: 60.0, metric: 'BRANCH', baseline: 'PROJECT', unstable: true]])
            }
        }

The plugin gives me a very clear report in the UI like this:

Screenshot 2023-06-27 at 18 05 12

But When i want to retrieve the information with a GET on the API mentioned in your doc (https://[jenkins-url]/job/[job-name]/[build-number]/coverage/api/json?pretty=true) I always got redirected to the build main page (from a browser) or just get nothing (from curl)

You can try (for a few days): http://load-balancer-jenkins-master-1462245991.ap-northeast-1.elb.amazonaws.com:8080/job/CI-Build/66/

Is there anything to do to activate this remote API?

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

No response

uhafner commented 1 year ago

There is a link at the bottom right (in the footer) of the coverage results page (not the job), there you can you open the remote API results.

E.g., https://ci.jenkins.io/job/Plugins/job/code-coverage-api-plugin/job/master/388/pit

has the following link in the footer:

https://ci.jenkins.io/job/Plugins/job/code-coverage-api-plugin/job/master/388/pit/api/

(This link actually has been redirected since remote calls have a security impact).

uhafner commented 1 year ago

I tried to open your link but it seems not to work...

JulienElkaim commented 1 year ago

Hello @uhafner sorry I had issues with my set up of AWS.

You can try for example this link now: http://load-balancer-jenkins-master-1462245991.ap-northeast-1.elb.amazonaws.com:8080/job/PRs%20-%20CI%20Build/job/babar/3/

I can't reach the ..../pit/api endpoint you mentioned :(

My main usage is to have a shields.io generated from this rest call, but for any reason just passing the job url (the one above) is not working with them. When I use Jacoco Plugin, shields.io is able to get the information and create the badge...

I would prefer to use Code Coverage API plugin, but for mysterious (and undocumented) reasons, it is not working even if it seems shields.io used ot support it :/

I am using 4.7.0

JulienElkaim commented 1 year ago

NVM

It now works, the specificity of my build is that I changed the ID, so shields.io did not recognize the path to use. SO it's not about your API, it is well functioning. Thank you @uhafner for the time taken !