5

我有一个使用 Github webhooks 触发的 Jenkins 声明性管道。

Jenkins 作业可以在拉取请求或合并时触发。

我希望每次都运行 3 个步骤中的 2 个(构建和测试)——合并和 PR。

我希望最后一步部署,仅在合并到“开发”分支时触发。

为此,我认为我需要访问触发该作业的 github webhook 有效负载(其主体和请求标头)。如何从声明性管道访问这些数据?

这是我想要的要点:

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'
            }
        }
    }
}

4

0 回答 0