Jenkins git commit for specific branch triggers build jobs for other branches too

We have a internal enterprise Github repo, and i have multiple feature branches.
I am facing a issue with triggering a build on a specific branch.
I have configured jobs for each of the feature branches. There is one jenkins job for one feature branch.
The first time i commit a code, it also triggers builds for jobs with other branches.

Steps to reproduce the problem:

  • Why does “git fetch” fail on HTTPS URLs with “Function is not available” on HP-UX?
  • Bash Search File for Pattern, Replace Pattern With Code that Includes Git Branch Name
  • Where can I report a git bug
  • Export only modified and added files with folder structure in Git
  • How do you manage git pre-commit hooks in a team in automated way?
  • Post-mortem unit testing
  • 1.We have a internal Github for enterprise. For my repo, i have setup webhook for github as below

     Settings -> Webhooks & Services -> Services
     Select Jenkins (GitHub plugin) 
     Jenkins Hook Url: http://************/jenkins/github-webhook/

    2.For my 3 branches in github repo : branch1, branch2, branch3, i created three jobs in jenkins:Job1, Job2, Job3 with SCM configured as below

    Source Code Management:
    Repo URL: git@********/********.git
    Branches to Build: refs/heads/BRANCH_NAME
    Build Trigger: Build when a change is pushed to GitHub

    3.On committing code to my branch : branch1. It triggers all the 3 jobs in jenkins: Job1, Job2, Job3.
    Note:This is the first time that the jobs were triggered.

    4.On committing code for the second time to branch: branch1. It triggers only Job1 in jenkins.

    It looks like first time all jobs are getting executed for the repo, irrespective of the branch.

    Details on my jenkins setup: Jenkins Version: 1.565.1, GitHub plugin: 1.9.1

    Any help/guidance to solve this issue is appreciated.

    FYI: I tried steps listed

  • How to git-pull all but one folder
  • unable to get SSH keys working between sourcetree and github
  • How do I delete a Git remote branch from the NetBeans IDE?
  • Why is the “Load putty key” field in TortoiseGit disabled?
  • How does Git create unique commit hashes, mainly the first few characters?
  • Git: copy all files in a directory from another branch
  • One Solution collect form web for “Jenkins git commit for specific branch triggers build jobs for other branches too”

    Make a script with the follow command (assuming your github SO is linux)

    curl http://yourserver/jenkins/git/notifyCommit?url=<URL of the Git repository>

    put this script in ./git/hooks

    In your jenkins jobs change

    “Build when a change is pushed to GitHub”

    To “Poll SCM”

    Don’t create any schedule in Poll SCM

    Git Baby is a git and github fan, let's start git clone.