1

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?

1
  • Maybe there's an error in your post-commit script? Can you post its contents or just have it contain a simple echo command to eradicate the possibility that your script contains a bug somewhere else. Commented Jan 16, 2018 at 14:21

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

But he's clearly stating that's he has made a commit.. "when I push something to the repository (and I see a commit has been made in the Git log of the remote repository "
Thank you very much! Post-receive was indeed what i needed.
@kingJulian When you push commits, the remote does not execute post-commit as no commit actions are actually made. post-commit executes locally when you commit, post-receive executes remotely on the server when that commit is pushed to the remote.
@crashmstr You're right. Thanks for clarifying it. I somehow didn't notice the part where th OP mentioned that he placed the script on the remote machine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.