简体   繁体   English

捆绑安装未从我的更新后挂钩运行

[英]bundle install not running from my post-update hook

I've setup a post-update hook for my project. 我已经为我的项目设置了更新后挂钩。 I have a bare repository (/var/git/myproject) which I push to, and a live repository (/var/www/myproject) where my app is running. 我有一个推送到的裸仓库(/ var / git / myproject),还有一个运行我的应用程序的实时仓库(/ var / www / myproject)。 I also included bundle install and bundle exec rake db:migrate to install gems and update db. 我还包括bundle installbundle exec rake db:migrate以安装gems和更新db。

Below is my post-update hook 以下是我的更新后挂钩

#!/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

When I push my changes though I get the following message (notice the "bundle command not found" error): 当我推送更改时,虽然收到以下消息(注意“未找到捆绑命令”错误):

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.

Why is bundle not running? 为什么捆绑包没有运行? I cd to the live app directory in the script. cd在脚本的实时应用程序的目录。 When I'm in terminal myself and I cd to the live directory and run bundle install it works so bundle is there. 当我在终端我自己和我cd到活动目录并运行bundle install ,运行非常束是存在的。

Your hook shell ins't the same than the one you logged in (and which has the proper PATH ) 您的钩子shell与您登录的钩子shell不同(钩子具有正确的PATH

You can try using at the beginning your your hook script: 您可以在开始时尝试使用挂钩脚本:

#!/bin/bash -l

(See this answer (请参阅此答案

The -l parameter executes the command in a login shell, which means that it inherits your path and other settings from your shell profile. -l参数在登录外壳程序中执行命令,这意味着它从外壳程序配置文件继承了您的路径和其他设置。

)

Or you can make sure your script gets the same environment than your current session, by adding in the first lines of your hook: 或者,您可以通过添加钩子的第一行来确保脚本获得与当前会话相同的环境:

$ source $HOME/.bash_profile # single user RVM setup
$ source /etc/profile        # multi user RVM setup

Or (final alternative) you can add (before calling bundle ) (for a single-user rvm installation) 或者(最终替代方案),您可以添加(在调用bundle之前)(对于单用户rvm安装)

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM