3

I have 3 Git branches, master, br2, and br3. I have 3 Jenkins jobs; each one clones the same repo but checks out a different branch. My understanding is that with the below command (http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/) in the post-receive hook it should trigger Jenkins to start the job for the branch the push was done on.

curl http://smfosbuild:8080/git/notifyCommit?url=git@vfilvgit2:scmtest.git

Changes made on br2 and pushed, the correct Jenkins job will start. But pushes for changes made on master or br3 will not cause the associate jobs to start.

I also have the email trigger active and I get an email for all pushes indicating the correct branch. So the post-receive hook is getting the correct info about the branch which has changed. Any ideas is my command above is incorrect or is there some setting in my Jenkins config I am missing?

robert
  • 33,242
  • 8
  • 53
  • 74
Scot
  • 61
  • 1
  • 5

2 Answers2

1

Well, in order to investigate that issue I would have to look into your GIT and Jenkins installation. But I can suggest an easier road in the meantime:

In a project configuration you can set up any build to be triggered remotely via a regular HTTP call (Job -> Configure -> Build Triggers -> Trigger builds remotely (e.g., from scripts)). This will not verify any repository information, but rather just execute the build no matter what. This is actually helpful, as the approach you described was causing us a lot of troubles as well. So, having this one up in the post-receive hook we're just calling the URL with the job name in it like that:

JENKINS_URL/job/Our$20Project%20-%20${BRANCH_NAME}/build?token=TOKEN_NAME

The branch name is the name of the branch, obviously.

Later on, when I took over that build, I made a change to use just one project to all of the branches and pass the branch name as a parameter. The branch is added to the build name (we're not using numbers any more) and it's much easier and a lot more flexible solution. But it won't suite everyone.

If you would like to I can provide you with a source code the post-receive hook, but it's really easy to write - we made that based on the post-receive-email available in Git sources.

Łukasz Rżanek
  • 5,786
  • 27
  • 37
  • Thanks Lukasz. I have done what you suggested as an interim solution; getting the branch name from the post-receive hook and calling my own script that creates the http call. This works great, but is not scaleable. It forces a naming convention in Jenkins - probably not a bad thing. Also I have 30+ repos and each one will need to be tweaked with the root of the Jenkins job name. And any change to a Jenkins job name brakes the trigger until the name change is done in the hook. So a very good suggestion, but I still want to get the recommended command to work for less future maintenance. – Scot May 11 '12 at 22:27
  • Then I'm really sorry, but without inspecting your Jenkins config and log files it will be really hard to fix this issue. If you would like to we can switch this to go by email and I will be glad to help you further. – Łukasz Rżanek May 11 '12 at 23:43
0

Did you know that even if you use the notification method described in Kohsuke's blog post, you need to have polling configured for the job? The polling interval can be something long, like "@daily", but it needs to be there because the notification is used just to trigger an immediate poll.

Also, your jobs need to use git repository "git@vfilvgit2:scmtest.git". Please double-check you are not using ssh://git@vfilvgit2/scmtest.git.

sti
  • 11,047
  • 1
  • 27
  • 27
  • Thanks, yes I have polling configured with a blank schedule - per what I have on the Jenkins blog this is okay. I have double checked and I am using git repository, not ssh://. – Scot May 14 '12 at 18:28