Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
缺少Git钩子环境变量_Git_Bash_Digital Ocean_Githooks_Pm2 - Fatal编程技术网

缺少Git钩子环境变量

缺少Git钩子环境变量,git,bash,digital-ocean,githooks,pm2,Git,Bash,Digital Ocean,Githooks,Pm2,我正在为Digital Ocean上的node应用程序创建一个自定义构建系统,其中涉及git钩子来安装依赖项并启动应用程序。应用程序配置的一部分从环境变量读取敏感数据(无法签入repo)。在我的git钩子中,我使用外部脚本停止应用程序,将repo文件(从SOURCE\u repo复制到SOURCE\u DIR(应该更好地命名变量)并重新启动应用程序: # hooks/post-receive # go to the www repo and stop the app cd $SOURCE_DIR

我正在为Digital Ocean上的node应用程序创建一个自定义构建系统,其中涉及git钩子来安装依赖项并启动应用程序。应用程序配置的一部分从环境变量读取敏感数据(无法签入repo)。在我的git钩子中,我使用外部脚本停止应用程序,将repo文件(从
SOURCE\u repo
复制到
SOURCE\u DIR
(应该更好地命名变量)并重新启动应用程序:

# hooks/post-receive
# go to the www repo and stop the app
cd $SOURCE_DIR
if [ -f tools/staging-stop.sh ]; then
    echo "Stopping the staging app..."
    tools/staging-stop.sh
fi

cd $SOURCE_REPO
git --work-tree=${SOURCE_DIR} checkout --force
cd $SOURCE_DIR

if [ -f tools/staging-start.sh ]; then
    echo "Starting the staging app..."
    tools/staging-start.sh
fi


# tools/staging-stop.sh
node_modules/.bin/pm2 stop staging
# updates env vars
node_modules/.bin/pm2 delete staging

# tools/stating-start.sh
source /etc/profile.d/my_env_vars.sh
yarn install --production=true
NODE_ENV=staging node_modules/.bin/pm2 start build/index.js --name staging
但是,由于一个原因,我无法精确指出
/etc/profile.d/my_env_vars.sh
中的环境变量(我认为这些变量应该在没有来源的情况下可用)在git钩子启动应用程序时不存在。但是,如果我
ssh
进入服务器并使用pm2手动启动应用程序,则环境变量可用,因此我猜这与git钩子本身及其启动的shell类型有关

我非常感谢你在这方面的帮助