如何在 git push 后运行 bash 脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16864259/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run bash script after git push
提问by VarunMurali
I wanted to know how to execute a bash script in the local repo after pushing to github.
我想知道如何在推送到 github 后在本地 repo 中执行 bash 脚本。
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.
bash 脚本位于文件夹的根目录中。我猜它可以根据被调用的位置移动。我研究过 git hooks,但没有 post-push hook,我不太了解其他 hooks。
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.
我试图在推送后调用 jenkins 构建。我已经研究了在 github 上使用 post-receive url 等推送后通知 jenkins 的方法,但似乎对我没有任何作用。
This is the script I'm trying to run:
这是我试图运行的脚本:
#!/bin/bash/
java -jar jenkins-cli.jar -s http://localhost:8080/ build Test
Thanks! Varun
谢谢!瓦伦
回答by cforbish
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.
这相当容易。有一个可以运行的脚本。您必须修改 .git/hooks/post-commit 才能找到需要运行的脚本。
mv .git/hooks/post-commit.sample .git/hooks/post-commit
vim .git/hooks/post-commit
I found this at: git-scm.com: Git Hooks
我在以下位置找到了这个: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:
如果没有.git/hooks/post-commit.sample
文件,没有问题,就.git/hooks/post-commit
从头开始创建(记得用 使脚本可执行chmod +x
),例如:
#!/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.
做一个测试提交,你应该看到脚本的输出,就在提交的常规输出之前。
回答by VarunMurali
I ended up using this answer here.
我最终在这里使用了这个答案。
https://stackoverflow.com/a/3812238/1490695
https://stackoverflow.com/a/3812238/1490695
Hope this helps!
希望这可以帮助!