jenkinsci / github-pr-coverage-status-plugin

Nice test coverage icon for your pull requests just from Jenkins
https://plugins.jenkins.io/github-pr-coverage-status/
Apache License 2.0
93 stars 101 forks source link

Please improve the documentation on usage of this plugin #118

Open sheetalj2205 opened 1 year ago

sheetalj2205 commented 1 year ago

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

I want to integrate code coverage reports of Jacoco into my GitHub PRs. I want to know do I need all the files of this repo also in my project for the integration or if I can simply use the code given in usage in Jenkinsfile in the example. Please check this question for complete desciption: Link

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

No response

rsov commented 1 year ago

You will need 3 things:

  1. Test runner that can output coverage/cobertura-coverage.xml file

  2. This in your jenkinsifle

    stage('Record Coverage') {
    when { branch 'main' }
    steps {
    script {
      currentBuild.result = 'SUCCESS'
    }
    step([$class: 'MasterCoverageAction', scmVars: [GIT_URL: env.GIT_URL]])
    }
    }
    stage('PR Coverage to Github') {
    when { allOf { not { branch 'main' }; expression { return env.CHANGE_ID != null } } }
    steps {
    script { currentBuild.result = 'SUCCESS' }
    
    // Don't fail whole pipeline if this step fails
    catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') {
      step([$class: 'CompareCoverageAction', publishResultAs: 'statusCheck', scmVars: [GIT_URL: env.GIT_URL]])
    }
    }
    }
  3. Branch protection on main branch for CI check Screenshot 2023-03-22 at 09 17 21