我有一个使用Github Webhooks触发的Jenkins声明性管道。
Jenkins作业可以在请求请求或合并中触发。
我希望每次都运行3个步骤(构建和测试)中的2个步骤-合并时和PR上都运行。
我希望最后一步Deploy仅在合并到“开发”分支中时触发。
为此,我认为我需要访问触发该作业的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'
}
}
}
}