13

I wanted to know how to execute a bash script in the local repo after pushing to github.

The bash script is located in the root of the folder. It can be moved around depending on where it is being called I guess. I have looked into git hooks but there is no post-push hook and I don't understand the other hooks very well.

I'm trying to call a jenkins build after the push. I have looked into ways of notifying jenkins after a push with post-receive url etc on github but nothing seems to work for me.

This is the script I'm trying to run:

#!/bin/bash/
java -jar jenkins-cli.jar -s http://localhost:8080/ build Test

Thanks! Varun

3

1 Answer 1

26

This is fairly easy. There is a script ready to run. You will have to modify .git/hooks/post-commit to find the script you need to run.

mv .git/hooks/post-commit.sample .git/hooks/post-commit
vim .git/hooks/post-commit

I found this at: git-scm.com: Git Hooks

If there is no .git/hooks/post-commit.sample file, not a problem, just create .git/hooks/post-commit from scratch (Remember to make the script executable with chmod +x), for example:

#!/bin/sh
echo look at me I am the post-commit script
pwd
# call the script you want

Do a test commit and you should see the output of the script, right before the regular output of the commit.

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

4 Comments

This isn’t for post push but rather for commits :|
How to call the script I wanna run in post-commit?
The OP need post push script, but this answer is post commit script
This answer is for run a script after commit, not after push. Downvote

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.