mlbright
mlbright

Reputation: 2202

How can I build both pull requests and merges to master with a single Jenkins pipeline build?

I have a Jenkinsfile that contains a step that deploys to production only when the build happens on the master branch. On pull requests, all the steps except the 'deploy' step happen. My problem is that builds are not kicked off automatically upon commits to master. How to kick off both master and pull request builds automatically?

Here is the crux of the 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'
            }
        }
    }
}
}

My Jenkins configuration looks like this:enter image description here

Upvotes: 1

Views: 311

Answers (1)

mlbright
mlbright

Reputation: 2202

This turns out to be a false alarm. Make sure your GitHub webhook is sending push events as well as pull request events to Jenkins.

Upvotes: 1

Related Questions