我已经为我的项目设置了一个更新后钩子。我有一个裸存储库(/var/git/myproject),我推到,和一个活动存储库(/var/www/myproject),我的应用程序正在运行。我还包括bundle install
和bundle exec rake db:migrate
来安装gems和更新db。
下面是我的更新后钩子
#!/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
当我推送更改时,我得到以下消息(注意"bundle command not found"错误):
martyn@localhost:~/www/myproject$ git push -u origin master
martyn@192.168.0.100'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.
为什么bundle没有运行?I cd
到脚本中的live app目录。当我自己在终端中,我把cd
放到live目录并运行bundle install
,它工作了,所以bundle在那里。
您的钩子外壳与您登录的不一样(并且具有正确的PATH
)
你可以尝试在你的钩子脚本的开头使用:
#!/bin/bash -l
(见答案
)
-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"