GitHub: How to configure required checks per Pipeline stage for Pull Requests

Issue

  • How to change the default status checks for protected branches in GitHub with information from my Pipeline?
  • I would like to set the status checks for protected branches in GitHub per stages of my Jenkinsfile.

Environment

Resolution

Prerequisite: GitHub Integration webhook for multibranch type of projects is configured as described in GitHub Integration: Webhooks – CloudBees Support

This issues is solved thanks to the CloudBees SCM Reporting Plugin which sends a GitHub Status check per Jenkinsfile stage definition

Example: The highlight of this example is that the remote status check depends on the build of a downstream job.

pipeline {
    agent any
    stages {
        stage ("local"){
            steps{
                sh "exit 0"
            }
        }
        stage("remote") {
            steps{
                build "my-team/folder-a/pipeline-1"
            }
        }
    }
}

On CloudBees CI side

1/ Install CloudBees SCM Reporting Plugin

2/ Configuring CloudBees SCM Reporting notifications

On GitHub side

After triggering the pipeline for the protected branches (the target branch for your Pull Request) following the configuration in (2/)

3/ Go to the repository Settings > protected branches > check Require status checks to pass before merging > Select the status check you wish to display for your Pull request.

Note The default stages from the GitHub plugin are:

  • continuous-integration/jenkins/branch
  • continuous-integration/jenkins/pr-merge

Tested products/plugins version

The latest update of this article was tested with:

Have more questions?

0 Comments

Please sign in to leave a comment.