【发布时间】:2019-10-05 04:19:27
【问题描述】:
我有一个 Jenkinsfile,其中包含一个步骤,仅当构建发生在主分支上时才会部署到生产环境。在拉取请求中,除了“部署”步骤之外的所有步骤都会发生。我的问题是构建不会在提交到 master 时自动启动。如何自动启动 master 和 pull request 构建?
这里是 Jenkinsfile 的关键:
pipeline {
agent { label "aws-build-agent" }
stages {
stage('scm') {
steps {
checkout scm
}
}
stage('build') {
steps {
sh './.cicd/build.sh'
}
}
stage('deploy') {
when { branch 'master' }
steps {
withCredentials(
[
sshUserPrivateKey(
credentialsId: "my-deploy-key",
keyFileVariable: 'RSA_PRIVATE_KEY_FILE'
)
]
) {
sh './.cicd/deploy.sh'
}
}
}
}
}
【问题讨论】:
-
考虑锁定
master分支并且只接受拉取请求而不是尝试支持直接合并。
标签: jenkins github continuous-integration jenkins-pipeline