Kohei Nozaki's blog 

Configuring automatic build by push for git repository


Posted on Sunday Mar 01, 2015 at 07:15PM in Jenkins


We can start the build by send request to following URL.

http://YOURHOST/jenkins/job/PROJECTNAME/build

Recipe

In my case, Jenkins is deployed in /, and the server is running on port 18080. so the command to start a build of the job named trader will be:

curl http://localhost:18080/job/trader/build

So put following shell script into $ORIGIN_BARE_REPOSITORY/hooks/post-receive and execute chmod +x post-receive.

#!/bin/sh
curl http://localhost:18080/job/trader/build

Testing

Push some modification as follows:

$ echo hook test >> hi.txt
$ git add hi.txt
$ git commit -m 'hook test'
$ git push origin master

Check the build was run automatically as expected, and the output.

b0731e82 30d0 4638 b412 1e1bba91d3c9



Comments:

This works fine if I have a single branch. What if I have 3 branches say v1.0, v2.0 & v3.0 and I push in v2.0. How do I ensure that when I push to v2.0 only that branch should be built.

Posted by Vipin on October 30, 2015 at 09:21 PM JST #


Hi Vipin thanks for the comment. Unfortunately I have no idea to ensure that. I recommend you to consult StackOverflow.

Posted by Kohei Nozaki on November 01, 2015 at 02:01 PM JST #


Leave a Comment

HTML Syntax: NOT allowed