我已经为我的项目设置了更新后挂钩。我有一个我推送到的裸存储库(/var/git/myproject),以及一个运行我的应用程序的实时存储库(/var/www/myproject)。我还包括bundle install
and bundle exec rake db:migrate
安装 gems 并更新数据库。
下面是我的更新后钩子
#!/bin/bash
echo "Pulling changes into Live..."
cd /var/www/myproject || exit
unset GIT_DIR
git pull origin master
# check if ruby app
if [ -f /var/www/myproject/Gemfile ];
then
echo " Ruby app detected..."
bundle install --without development test
bundle exec rake db:migrate # migrate database
fi
exec git-update-server-info
当我推送更改时,我收到以下消息(请注意“找不到捆绑命令”错误):
martyn@localhost:~/www/myproject$ git push -u origin master
[email protected] /cdn-cgi/l/email-protection's password:
Counting objects: 832, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (783/783), done.
Writing objects: 100% (832/832), 487.70 KiB, done.
Total 832 (delta 434), reused 0 (delta 0)
remote: Pulling changes into Live...
remote: From /var/git/myproject
remote: * branch master -> FETCH_HEAD
remote: Ruby app detected...
remote: hooks/post-update: line 13: bundle: command not found
remote: hooks/post-update: line 14: bundle: command not found
To 192.168.24.100:/var/git/myproject.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
为什么捆绑包没有运行?我cd
到脚本中的实时应用程序目录。当我自己在航站楼时cd
到 live 目录并运行bundle install
它有效,所以捆绑就在那里。
您的钩子外壳与您登录的外壳不同(并且具有正确的PATH
)
您可以尝试在开始时使用您的挂钩脚本:
#!/bin/bash -l
(See 这个答案 https://stackoverflow.com/a/12347966/6309
The -l
参数在登录 shell 中执行命令,这意味着它从 shell 配置文件继承您的路径和其他设置。
)
或者,您可以通过添加挂钩的第一行来确保您的脚本获得与当前会话相同的环境:
$ source $HOME/.bash_profile # single user RVM setup
$ source /etc/profile # multi user RVM setup
或者(最后的选择)你可以添加(在调用之前bundle
)(对于单用户 rvm 安装)
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)