I spent quite some time figuring this out, but was happy when it worked. This is for Windows. In Linux, the process is the same, but it's far easier.
First, you have to know that if you've installed Git in Windows, it comes with curl pre-installed. So just open the Git bash prompt and start typing your commands.
Let's say you have a Jenkins job setup on localhost, named "someJob". To initiate a build, just type the following command in the Git Bash prompt:
curl http://localhost:8080/job/someJob/build?delay=0sec
That's it. Once you've typed the command, just have a look at your Jenkins dashboard and you'll see your project building. (you might also want to know about this)
Now to make a Git commit trigger the build, you have to navigate to the hidden ".git" directory in your git repository. Enter the "hooks" directory and you'll see there, a "post-commit.sample" file. You can open it with Notepad++ to see the contents of it.
Make a copy of the file and name it "post-commit". It does not need an extension. This is the file that Git will invoke whenever you do a commit to this particular Git repository. Don't worry about the fact that it looks like a Linux bash script. When Git triggers it, it will run even in Windows. If the file has a line ": Nothing", you can remove that line and insert this new line:
curl http://localhost:8080/job/someJob/build?delay=0sec
Now save the file, make some changes to your git repository and commit the changes. The moment you commit, you'll see the build being triggered in Jenkins! Awesome! :)
Additional note: Many people reach this page via a StackOverflow answer. One such person (see comment below answer) mentioned being confused about what "someJob" was and also had faced an issue with his project name having a space in between, so he had to substitute "%20" in place of a space "codecept%20tests". Hope his response would be of help to anyone else who faces a similar situation. Thank you Paul.
First, you have to know that if you've installed Git in Windows, it comes with curl pre-installed. So just open the Git bash prompt and start typing your commands.
Let's say you have a Jenkins job setup on localhost, named "someJob". To initiate a build, just type the following command in the Git Bash prompt:
curl http://localhost:8080/job/someJob/build?delay=0sec
That's it. Once you've typed the command, just have a look at your Jenkins dashboard and you'll see your project building. (you might also want to know about this)
Now to make a Git commit trigger the build, you have to navigate to the hidden ".git" directory in your git repository. Enter the "hooks" directory and you'll see there, a "post-commit.sample" file. You can open it with Notepad++ to see the contents of it.
Make a copy of the file and name it "post-commit". It does not need an extension. This is the file that Git will invoke whenever you do a commit to this particular Git repository. Don't worry about the fact that it looks like a Linux bash script. When Git triggers it, it will run even in Windows. If the file has a line ": Nothing", you can remove that line and insert this new line:
curl http://localhost:8080/job/someJob/build?delay=0sec
Now save the file, make some changes to your git repository and commit the changes. The moment you commit, you'll see the build being triggered in Jenkins! Awesome! :)
-----------------------------------------------------------------
Additional note: Many people reach this page via a StackOverflow answer. One such person (see comment below answer) mentioned being confused about what "someJob" was and also had faced an issue with his project name having a space in between, so he had to substitute "%20" in place of a space "codecept%20tests". Hope his response would be of help to anyone else who faces a similar situation. Thank you Paul.