Santosh Dhanasure
Santosh Dhanasure

Reputation: 1013

Jenkins Git-Push with master branch only

This might be a very basic question in terms of jenkins and github integration. However, I am thinking good to ask.

What I am basically looking to do is if anything pushed to master branch of git only then my jenkins job must get triggered. Considering there are multiple feature branches and multiple commits happening on different branches but I am interested only in master branch push.

I did not find good documentation over, could anybody give me any pointer on this.

Help is appreciated, thanks!

Upvotes: 2

Views: 1303

Answers (1)

Michael
Michael

Reputation: 2683

OK, so you got two options:

Create a single branch pipeline

Just click on create new item, select pipeline and under "Pipeline" configure as "Pipeline script from SCM" and put your GitHub and in "branches to build" put "*/master".

Add brach conditions

Alternatively you could add when conditions to your stages if you use declarative syntax:

pipeline {

    agent any

    stages {

        stage("Build") {
            when { branch 'master' }
            steps {
                // do your build
            }
        }
    }
}

Or if you're using scripted:

node {
    stage('Build') {
        if (env.BRANCH_NAME == 'master') {
            // do your build
        }
    }
}

See "flow control".

Upvotes: 1

Related Questions