如何在git push之后运行bash脚本

Var*_*ali 12 git bash hook github githooks

我想知道如何在推送到github后在本地仓库中执行bash脚本.

bash脚本位于文件夹的根目录中.它可以根据我猜的调用位置移动.我已经研究过git hooks但是没有后推钩,我不太了解其他钩子.

我试图在推动之后调用jenkins构建.我已经研究过在github上使用post-receive url等推送后通知jenkins的方法,但似乎没有什么对我有用.

这是我正在尝试运行的脚本:

#!/bin/bash/
java -jar jenkins-cli.jar -s http://localhost:8080/ build Test
Run Code Online (Sandbox Code Playgroud)

谢谢!Varun的

cfo*_*ish 23

这很容易.有一个准备运行的脚本.您必须修改.git/hooks/post-commit才能找到需要运行的脚本.

mv .git/hooks/post-commit.sample .git/hooks/post-commit
vim .git/hooks/post-commit
Run Code Online (Sandbox Code Playgroud)

我发现了这个:git-scm.com:Git Hooks

如果没有.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
Run Code Online (Sandbox Code Playgroud)

执行测试提交,您应该在提交的常规输出之前看到脚本的输出.

  • 这不是为了推送而是为了提交:| (11认同)
  • 这个答案是在提交后运行脚本,而不是在推送后运行。投反对票 (2认同)