求助解决Bitbucket Pipeline报错:vendor/bin/phpunit: No such file or directory
问题根源
Bitbucket Pipeline的每个步骤都是独立运行的Docker容器,容器之间默认不会共享文件系统。你在Install Dependencies步骤中通过composer install生成的vendor目录,只会存在于该步骤的容器中,后续的Run Tests步骤无法访问到这个目录,因此出现找不到vendor/bin/phpunit的错误。
解决方案
最合理的做法是使用Bitbucket的**工件(Artifacts)**功能,将Install Dependencies步骤生成的vendor目录传递给后续需要它的步骤。修改你的Pipeline配置如下:
image: php:8.0 pipelines: branches: stage: - step: name: Install Dependencies caches: - composer - node script: - apt-get update && apt-get install -y unzip libpng-dev libjpeg-dev libfreetype6-dev - docker-php-ext-configure gd --with-freetype --with-jpeg - docker-php-ext-install gd - curl -sS https://getcomposer.org/installer | php - mv composer.phar /usr/local/bin/composer - composer install --no-scripts - curl -sL https://deb.nodesource.com/setup_16.x | bash - - apt-get install -y nodejs - npm install --legacy-peer-deps # 添加工件配置,传递vendor和node_modules到后续步骤 artifacts: - vendor/** - node_modules/** - step: name: Run Tests script: - vendor/bin/phpunit - step: name: Build Assets caches: - node script: - npm run prod - step: name: Migrate Database script: - php artisan migrate --force - php artisan key:generate - php artisan jwt:secret services: - mysql definitions: services: mysql: image: mysql:5.7 caches: composer: ~/.composer/cache node: ~/.npm
额外检查点
- 确认你的
composer.json文件中已经包含phpunit/phpunit作为开发依赖项,否则composer install不会将其安装到vendor/bin目录下。 - 如果你不需要拆分步骤,也可以将
Run Tests的命令直接合并到Install Dependencies步骤中,这样就无需传递工件,但这种方式不利于步骤的模块化管理。
内容的提问来源于stack exchange,提问作者ST80
相关产品推荐
相关产品推荐

