【问题标题】:How can I build both pull requests and merges to master with a single Jenkins pipeline build?如何通过单个 Jenkins 管道构建同时构建拉取请求和合并以掌握?
【发布时间】: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'
            }
        }
    }
}
}

我的 Jenkins 配置如下所示:

【问题讨论】:

  • 考虑锁定master 分支并且只接受拉取请求而不是尝试支持直接合并。

标签: jenkins github continuous-integration jenkins-pipeline


【解决方案1】:

事实证明这是一场虚惊。确保您的 GitHub webhook 正在向 Jenkins 发送 push 事件和 pull request 事件。

【讨论】:

    猜你喜欢
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-11
    • 1970-01-01
    • 2019-08-29
    • 2016-07-21
    • 2020-01-01
    相关资源
    最近更新 更多