jenkinsci / github-pr-coverage-status-plugin

Nice test coverage icon for your pull requests just from Jenkins

Home Page:https://plugins.jenkins.io/github-pr-coverage-status/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Please improve the documentation on usage of this plugin

sheetalj2205 opened this issue · comments

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

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]])
    }
  }
}
  1. Branch protection on main branch for CI check
    Screenshot 2023-03-22 at 09 17 21