<p>I don't think I can help you with this, but I think I can suggest you where to look for a relevant information.</p>

<ol>
<li>You can report any status check to your PR using Status API (<a href="https://developer.github.com/v3/repos/statuses/" rel="nofollow noreferrer">https://developer.github.com/v3/repos/statuses/</a>)</li>
<li>You can configure which Status checks are required from PR (<a href="https://help.github.com/en/github/administering-a-repository/about-required-status-checks" rel="nofollow noreferrer">https://help.github.com/en/github/administering-a-repository/about-required-status-checks</a>)</li>
<li>Since pipeline is actually groovy code, calling Status API should not be a challenge. (Example with CURL - <a href="https://www.openmakesoftware.com/restful-json-api-calls-jenkins-pipeline/" rel="nofollow noreferrer">https://www.openmakesoftware.com/restful-json-api-calls-jenkins-pipeline/</a>, example using native groovy - <a href="https://www.deployhub.com/native-groovy-api/" rel="nofollow noreferrer">https://www.deployhub.com/native-groovy-api/</a>)</li>
</ol>

CC BY-SA 4.0
2020-03-02T09:53:13.683Z
2020-03-02T09:53:13.683Z
Alexander Pushkarev
<p>We have a parallel Jenkins pipeline script which deploy and run three kind of tests in parallel. We have to notify the status of each stage to GitHub pull request. Can anyone help me to get this?</p>

<pre><code>def jobs = [
    [
        "name" : "LegacyUnitTests",
        "runFolder" : "recipes",
        "run"   : { -&gt; sh "docker-compose -f docker-compose/docker-compose-maven.yml -f docker-compose/docker-compose.yml run maven-unit-test" },
        "report": { -&gt; junit testResults: "docker-compose/volmnt/reports/*.xml" },
    ],
    [
        "name" : "AutomationTests",
        "runFolder" : "automation",
        "run"   : { -&gt; sh "../run_automation_tests.sh" },
        "report": { -&gt;
            junit testResults: "reports/junit/*.xml"
            allure([
                includeProperties: false,
                jdk: '',
                properties: [],
                reportBuildPolicy: 'ALWAYS',
                results: [[path: '/reports/allure']]
            ])
        }
    ]
]

def parallelStagesMap = jobs.collectEntries {
    ["${it.name}" : generateStage(it)]
}

def generateStage(job) {
    return {
        stage(job.name) {
            dir(job.runFolder) {
                try {
                    job.run.call()
                    setSuccess(this, job.name)
                }
                catch (err) {
                    setFailed(this, job.name)
                }
            }
       }
   }
}

pipeline {
    agent {
        node {
            label 'pr-slave-test'
            customWorkspace "/var/lib/jenkins/workspace/${JOB_NAME}_${BUILD_NUMBER}"
        }
    }
    post {
        always {
            //Reports
            script {
                jobs.each {
                    j -&gt; j.report.call()
                }
            }//Cleanup
            cleanWs()
        }
    }
    stages {
        stage('Pre-Build') {
            steps {
                 script {
                    //set status as pending
                    jobs.each {
                        j -&gt; setPending(this, j.name)
                    }
                    //checkout all repo   
                 }
            }
        }
        stage('Build') {
            steps {
                dir () {
                    sh "echo \"Building\""
                }
            }
        }
        stage('CI') {
            steps {
                script {
                    parallel parallelStagesMap
                }
            }
        }
    }
}
</code></pre>

<p>I want to notify GitHub pr for each stage automation and legacy unit test status as pass fail as a GitHub check status</p>

<jenkins-pipeline><github>
How do i notify GitHub pull request for each stage of a parallel Jenkins pipeline?
ADHITHYA SRINIVASAN
# How do i notify GitHub pull request for each stage of a parallel Jenkins pipeline?

(Asked by: username_0 on 2020-02-15)

We have a parallel Jenkins pipeline script which deploy and run three kind of tests in parallel. We have to notify the status of each stage to GitHub pull request. Can anyone help me to get this?
def jobs = [
    [
        "name" : "LegacyUnitTests",
        "runFolder" : "recipes",
        "run"   : { -> sh "docker-compose -f docker-compose/docker-compose-maven.yml -f docker-compose/docker-compose.yml run maven-unit-test" },
        "report": { -> junit testResults: "docker-compose/volmnt/reports/*.xml" },
    ],
    [
        "name" : "AutomationTests",
        "runFolder" : "automation",
        "run"   : { -> sh "../run_automation_tests.sh" },
        "report": { ->
            junit testResults: "reports/junit/*.xml"
            allure([
                includeProperties: false,
                jdk: '',
                properties: [],
                reportBuildPolicy: 'ALWAYS',
                results: [[path: '/reports/allure']]
            ])
        }
    ]
]

def parallelStagesMap = jobs.collectEntries {
    ["${it.name}" : generateStage(it)]
}

def generateStage(job) {
    return {
        stage(job.name) {
            dir(job.runFolder) {
                try {
                    job.run.call()
                    setSuccess(this, job.name)
                }
                catch (err) {
                    setFailed(this, job.name)
                }
            }
       }
   }
}

pipeline {
    agent {
        node {
            label 'pr-slave-test'
            customWorkspace "/var/lib/jenkins/workspace/${JOB_NAME}_${BUILD_NUMBER}"
        }
    }
    post {
        always {
            //Reports
            script {
                jobs.each {
                    j -> j.report.call()
                }
            }//Cleanup
            cleanWs()
        }
    }
    stages {
        stage('Pre-Build') {
            steps {
                 script {
                    //set status as pending
                    jobs.each {
                        j -> setPending(this, j.name)
                    }
                    //checkout all repo   
                 }
            }
        }
        stage('Build') {
            steps {
                dir () {
                    sh "echo \"Building\""
                }
            }
        }
        stage('CI') {
            steps {
                script {
                    parallel parallelStagesMap
                }
            }
        }
    }
}

I want to notify GitHub pr for each stage automation and legacy unit test status as pass fail as a GitHub check status

**Tags:** jenkins-pipeline, github


---

## 1 answers

### Answer by username_1 on 2020-03-02. Score: 1

I don't think I can help you with this, but I think I can suggest you where to look for a relevant information.

1. You can report any status check to your PR using Status API (<https://developer.github.com/v3/repos/statuses/>)
2. You can configure which Status checks are required from PR (<https://help.github.com/en/github/administering-a-repository/about-required-status-checks>)
3. Since pipeline is actually groovy code, calling Status API should not be a challenge. (Example with CURL - <https://www.openmakesoftware.com/restful-json-api-calls-jenkins-pipeline/>, example using native groovy - <https://www.deployhub.com/native-groovy-api/>)


---

