【问题标题】:How to run bash script after git push如何在 git push 之后运行 bash 脚本
【发布时间】:2013-05-27 16:28:49
【问题描述】:

我想知道如何在推送到 github 后在本地 repo 中执行 bash 脚本。

bash 脚本位于文件夹的根目录中。我猜它可以根据被调用的位置来移动。 我研究过 git 钩子,但没有 post-push 钩子,我不太了解其他钩子。

我正在尝试在推送后调用 jenkins 构建。我已经研究了在 github 上使用 post-receive url 等推送后通知 jenkins 的方法,但似乎对我没有任何作用。

这是我要运行的脚本:

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

谢谢! 瓦伦

【问题讨论】:

标签: git bash github hook githooks


【解决方案1】:

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

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

我在以下位置找到了这个: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

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

【讨论】:

  • 这不是用于后期推送,而是用于提交:|
  • 提交后如何调用我想运行的脚本?
  • OP 需要 post push 脚本,但这个答案是 post commit script
  • 这个答案是在提交后运行脚本,而不是在推送后运行。投反对票
猜你喜欢
  • 2013-08-13
  • 2014-10-08
  • 2018-04-17
  • 2016-07-23
  • 2015-04-09
  • 2019-08-19
  • 2013-10-24
  • 2012-09-07
  • 2017-01-01
相关资源
最近更新 更多