The HOME or COMPOSER_HOME environment variable must be set for composer to run

2019-10-15

在saltstack远程将项目composer 做dump优化的时候碰到如下错误提示

17:17:23 [SSH] executing…
17:17:26 ERROR: Minions returned with non-zero exit code
17:17:26 xxxxxxxxxxxxxxxx:
17:17:26
17:17:26
17:17:26 [RuntimeException]
17:17:26 The HOME or COMPOSER_HOME environment variable must be set for composer to run correctly
17:17:26
17:17:26 [SSH] completed
17:17:26 [SSH] exit-status: 11
17:17:26
17:17:26 Build step ‘Execute shell script on remote host using ssh’ marked build as failure

原来命令:

cd /home/xxx/xxxx/ && /usr/local/php/bin/php ./Bin/composer dump-autoload -o -a –no-dev

经过检测发现是HOME和COMPOSER_HOME没有设置,改为

cd /home/xxxx/xxx/ && HOME=”/home/xxxx” COMPOSER_HOME=”/home/xxxx/.config/composer” /usr/local/php/bin/php ./Bin/composer dump-autoload -o -a –no-dev

即可解决,composer需要这个目录写cache而很多环境变量在saltstack这里没有设置,导致此问题