简体   繁体   中英

Git post-commit hook not triggered

I wrote a file named post-commit (no file extension, executable, owned by the git user) with a standard bash script to trigger a Jenkins build on another server and placed it in directory git/ProjectName/hooks in our remote repository. When I manually execute the file as user git ( ./post-commit ).

The Jenkins build starts. But when I push something to the repository (and I see a commit has been made in the Git log of the remote repository) the post-commit file is not executed (I check by placing an echo command in the file).

Why post-commit file does not execute?

The post-commit hook does not get executed on the remote because a commit was not made on the remote.

What you need is a post-receive hook on the server.

https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks

Server-Side Hooks In addition to the client-side hooks, you can use a couple of important server-side hooks as a system administrator to enforce nearly any kind of policy for your project. These scripts run before and after pushes to the server.
...
post-receive
The post-receive hook runs after the entire process is completed and can be used to update other services or notify users. It takes the same stdin data as the pre-receive hook. Examples include e-mailing a list, notifying a continuous integration server, or updating a ticket-tracking system – you can even parse the commit messages to see if any tickets need to be opened, modified, or closed. This script can't stop the push process, but the client doesn't disconnect until it has completed, so be careful if you try to do anything that may take a long time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM