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

usage of recordCoverage twice in different stage #749

Closed xpicio closed 1 year ago

xpicio commented 1 year ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.419 OS: Linux - 5.10.176+ Java: 17.0.8 - Eclipse Adoptium (OpenJDK 64-Bit Server VM) --- ansicolor:1.0.2 antisamy-markup-formatter:159.v25b_c67cd35fb_ apache-httpcomponents-client-4-api:4.5.14-150.v7a_b_9d17134a_5 authentication-tokens:1.53.v1c90fd9191a_b_ blueocean:1.27.5.1 blueocean-autofavorite:1.2.5 blueocean-bitbucket-pipeline:1.27.5.1 blueocean-commons:1.27.5.1 blueocean-config:1.27.5.1 blueocean-core-js:1.27.5.1 blueocean-dashboard:1.27.5.1 blueocean-display-url:2.4.2 blueocean-events:1.27.5.1 blueocean-git-pipeline:1.27.5.1 blueocean-github-pipeline:1.27.5.1 blueocean-i18n:1.27.5.1 blueocean-jwt:1.27.5.1 blueocean-personalization:1.27.5.1 blueocean-pipeline-api-impl:1.27.5.1 blueocean-pipeline-editor:1.27.5.1 blueocean-pipeline-scm-api:1.27.5.1 blueocean-rest:1.27.5.1 blueocean-rest-impl:1.27.5.1 blueocean-web:1.27.5.1 bootstrap5-api:5.3.0-1 bouncycastle-api:2.29 branch-api:2.1122.v09cb_8ea_8a_724 build-discarder:139.v05696a_7fe240 caffeine-api:3.1.8-133.v17b_1ff2e0599 checks-api:2.0.0 cloudbees-bitbucket-branch-source:825.va_6a_dc46a_f97d cloudbees-folder:6.848.ve3b_fd7839a_81 code-coverage-api:4.7.0 command-launcher:1.2 commons-httpclient3-api:3.1-3 commons-lang3-api:3.13.0-62.v7d18e55f51e2 commons-text-api:1.10.0-68.v0d0b_c439292b_ configuration-as-code:1670.v564dc8b_982d0 credentials:1271.v54b_1c2c6388a_ credentials-binding:631.v861c06d062b_4 cucumber-reports:5.7.5 dark-theme:315.va_22e7d692ea_a data-tables-api:1.13.5-1 dependency-track:4.3.1 display-url-api:2.3.8 durable-task:513.vc48a_a_075a_d93 echarts-api:5.4.0-4 email-ext:2.99 favorite:2.4.3 font-awesome-api:6.4.0-2 forensics-api:2.3.0 generic-webhook-trigger:1.86.4 git:5.2.0 git-client:4.4.0 git-forensics:2.0.0 git-server:1.11 github:1.37.1 github-api:1.314-431.v78d72a_3fe4c3 github-branch-source:1728.v859147241f49 github-checks:1.0.19 gravatar:2.2 handy-uri-templates-2-api:2.1.8-22.v77d5b_75e6953 htmlpublisher:1.32 http_request:1.18 instance-identity:142.v04572ca_5b_265 ionicons-api:56.v1b_1c8c49374e jackson2-api:2.15.2-350.v0c2f3f8fc595 jakarta-activation-api:2.0.1-3 jakarta-mail-api:2.0.1-3 javax-activation-api:1.2.0-6 javax-mail-api:1.6.2-7 jaxb:2.3.8-1 jdk-tool:1.5 jenkins-design-language:1.27.5.1 jersey2-api:2.40-1 jjwt-api:0.11.5-77.v646c772fddb_0 jquery3-api:3.7.0-1 jsch:0.1.55.61.va_e9ee26616e7 junit:1217.v4297208a_a_b_ce kubernetes:3971.v94b_4c914ca_75 kubernetes-client-api:6.4.1-215.v2ed17097a_8e9 kubernetes-credentials:0.10.0 locale:314.v22ce953dfe9e lockable-resources:1172.v4b_8fc8eed570 mailer:457.v3f72cb_e015e5 material-theme:0.5.2-rc100.6121925fe229 matrix-auth:3.0.1 matrix-project:808.v5a_b_5f56d6966 metrics:4.2.18-442.v02e107157925 mina-sshd-api-common:2.10.0-69.v28e3e36d18eb_ mina-sshd-api-core:2.10.0-69.v28e3e36d18eb_ nexus-artifact-uploader:2.14 okhttp-api:4.11.0-157.v6852a_a_fa_ec11 pipeline-build-step:505.v5f0844d8d126 pipeline-graph-analysis:202.va_d268e64deb_3 pipeline-groovy-lib:671.v07c339c842e8 pipeline-input-step:477.v339683a_8d55e pipeline-milestone-step:111.v449306f708b_7 pipeline-model-api:2.2144.v077a_d1928a_40 pipeline-model-definition:2.2144.v077a_d1928a_40 pipeline-model-extensions:2.2144.v077a_d1928a_40 pipeline-rest-api:2.33 pipeline-stage-step:305.ve96d0205c1c6 pipeline-stage-tags-metadata:2.2144.v077a_d1928a_40 pipeline-stage-view:2.33 pipeline-utility-steps:2.16.0 plain-credentials:143.v1b_df8b_d3b_e48 plugin-util-api:3.3.0 prism-api:1.29.0-7 pubsub-light:1.17 resource-disposer:0.22 role-strategy:587.588.v850a_20a_30162 scm-api:676.v886669a_199a_a_ scmskip:1.0.3 script-security:1269.v639888f5e366 snakeyaml-api:1.33-95.va_b_a_e3e47b_fa_4 solarized-theme:0.1 sse-gateway:1.26 ssh-agent:333.v878b_53c89511 ssh-credentials:308.ve4497b_ccd8f4 sshd:3.237.v883d165a_c1d3 structs:324.va_f5d6774f3a_d theme-manager:193.vcef22f6c5f2b_ token-macro:384.vf35b_f26814ec trilead-api:2.84.v72119de229b_7 variant:59.vf075fe829ccb workflow-aggregator:596.v8c21c963d92d workflow-api:1259.vb_47f14fffc8a_ workflow-basic-steps:1042.ve7b_140c4a_e0c workflow-cps:3744.v6f2c0fe0e54d workflow-durable-task-step:1284.v4fcd365b_75b_e workflow-job:1326.ve643e00e9220 workflow-multibranch:756.v891d88f2cd46 workflow-scm-step:415.v434365564324 workflow-step-api:639.v6eca_cd8c04a_a_ workflow-support:848.v5a_383b_d14921 ws-cleanup:0.45 ```

What Operating System are you using (both controller, and any agents involved in the problem)?

Jenkins is installed on k8s cluster, the server is based on public container image jenkins/jenkins:2.419-jdk17, the agent is based on jenkins/inbound-agent:3107.v665000b_51092-4-jdk17

Reproduction steps

Run recordCoverage within different stage

      stage('Unit test') {
        agent {
          kubernetes {
            yamlMergeStrategy merge()
            inheritFrom nodeToolsPodTemplateName
            yaml utilities.dedicatedJenkinsAgentNodeYaml()
          }
        }    
        steps {
          unstash 'app'

          container(nodeToolsContainerName) {
            script {
              nodeUtilities.build(projectRootDirectory, 'pnpm')

              sh '''
                pnpm test:unit
              '''
            }
          }
        }
        post {
          always {
            junit testResults: 'generated/test-unit/report.xml', allowEmptyResults: true
            recordCoverage tools: [[
              parser: 'COBERTURA',
              pattern: 'generated/test-unit-coverage/cobertura-coverage.xml'
            ]],
            sourceCodeRetention: 'EVERY_BUILD',
            sourceDirectories: [[path: projectRootDirectory]]            
          }
        }
      }
      stage('Integration test') {
        agent {
          kubernetes {
            yamlMergeStrategy merge()
            inheritFrom integrationTestContainers(nodeToolsPodTemplateName, deploymentSettings.settings.integrationTest.containers)
            yaml utilities.dedicatedJenkinsAgentNodeYaml()
          }
        }    
        steps {
          unstash 'app'

          container(nodeToolsContainerName) {
            script {
              nodeUtilities.build(projectRootDirectory, 'pnpm')

              sh '''              
                pnpm test:integration                
              '''
            }
          }
        }
        post {
          always {
            junit testResults: 'generated/test-integration/report.xml', allowEmptyResults: true
            recordCoverage tools: [[
              parser: 'COBERTURA',
              pattern: 'generated/test-integration-coverage/cobertura-coverage.xml'
            ]],
            sourceCodeRetention: 'EVERY_BUILD',
            sourceDirectories: [[path: projectRootDirectory]]            
          }
        }            
      }

Expected Results

The reports from stage Unit test and Integration test should be merged to one Coverage report and Code coverage trend

Actual Results

There are multiple entry in the pipeline status for Code coverage trend and Coverage report, however the links of these items is always the same https://jenkins.example.com/view/Backend/job/energy-meter-srv-test/{build-id}/coverage.

code-coverage-trend

coverage-report

Anything else?

To be honest i'm not sure that is a bug, but let me know if it's possible run recordCoverage multiple times in a pipeline or is not possibile do it.

Have a nice day

uhafner commented 1 year ago

When you are using the same step multiple times, then you need to specify different IDs and names, so that you can access all of them.

Merging currently is only supported in a single step, you need to specify a pattern that matches all results.

xpicio commented 1 year ago

ok, thank you for the answer. I will try with a different strategy 👍