1

guys!! I'm trying to set up Jenkins-ci for a project that uses GIT as a local version control of my repositories. I've already set up jenkins with the appropriate plugins. I want jenkins to run build scripts only whenever someone on the project pushes to master, just only can get information to GitHub,GitLab,etc but it is useless. So far I've been able to set it up so that a build will be triggered anytime anyone pushes to anywhere.

I would like to know how set up a Jenkins' task to build automatically a project when make git push to my repository

1 Answers1

1

According to the Git Plugin Documentation, you need to set up a post-recieve hook for git to notify jenkins when your repo is pushed to.

curl http://yourserver/git/notifyCommit?url=<URL of the Git repository>[&branches=branch1[,branch2]*][&sha1=<commit ID>]

On the jenkins side, set your job to point to the repo and branches you want to build, and turn on Build Triggers > Poll SCM (don't fill in the schedule field). Oh, and set branches to build to master.

Brandon McKenzie
  • 1,655
  • 11
  • 26
  • You shouldn't need a hook if you are polling. As your're interested in master, ensure you configured it ("Branches to build"). – Gustave Aug 05 '15 at 12:37
  • 1
    Per the documentation in my answer, marking poll SCM serves only to identify jobs to be notified of git pushes to the Git Plugin. The post-receive hook is what actually tells Jenkins to build, as opposed to polling results (hence why a schedule is not needed, and should not be filled in). For further detail, here is a [blog post](http://kohsuke.org/2011/12/01/polling-must-die-triggering-jenkins-builds-from-a-git-hook/) from the Git Plugin Author, that was created around the time this functionality was implemented. – Brandon McKenzie Aug 05 '15 at 15:11