The standard way of triggering Jenkins jobs from a git repository was issuing a get request on the “build now” URL of the job in the post-receive
hook, e.g.
curl http://my_ci_server:8080/job/my_job/build?delay=0sec
The biggest problem of this approach is that you have to hardcode the job name into the url. This prevents sharing the hook between repositories and requires you to put an adjusted post-receive hook script into each new repository. Also, additional work has to be done to trigger jobs only for certain branches and the like.
Fortunately, Jenkins offers a new way of triggering jobs from a git repository for quite a while now. Essentially you have to notify jenkins of the commit in your repository and configure the job for polling.
To trigger jobs for the repository git@my_repository_server:my_project.git
you can use the following script:
GIT_REPO_URL=git@my_repository_server:`pwd | sed 's:.*\/::'` curl http://my_ci_server:8080/git/notifyCommit?url=$GIT_REPO_URL
Notice the absence of any repository or job specific stuff in the post-receive hook. Such a hook can be placed in a central location and be shared between repositories using symbolic links.
What happens if you have repos in my_repository_server that should not trigger builds?
The post-receive hook is per repository. So only repositories that should trigger build have to link the script. The others simply do not have such a post-receive script linked.
https://stackoverflow.com/questions/48863904/jenkins-included-and-excluded-regions-are-not-working
Can u please help me out with this?