I have a Jenkins declarative pipeline that is triggered using Github webhooks.
The Jenkins job can be triggered either on a pull request or a merge.
I want 2 of the 3 steps (Build and Test) to be run every time -- both a on a merge and a PR.
I want the final step, Deploy, only to be triggered on merges into the 'development' branch.
To do this, I believe I need to access to the github webhook payload (both its body and request headers) that triggered the job. How can I access this data from the declarative pipeline?
Here's the gist of what I want:
pipeline {
    agent any
    stages {
        stage ('Build') {
            steps {
                sh 'build.sh'
            }
        }
        stage ('Test') {
            steps {
                sh 'test.sh'
            }
        }
        stage ('Deploy to QA') {
            when {
                branch 'development'
                // AND the github webhook header "X-GitHub-Event" == "pull_request"
                // AND the github webhook json payload body.merged == true
            }
            steps {
                sh 'deploy-to-qa.sh'
            }
        }
    }
}
