在 GitLab 的 CI / CD 的 Pipelines 中,Build composer 失败

1、在 GitLab 的 CI / CD 的 Pipelines 中,Build composer 失败。如图1

图1

$ php artisan key:generate

In DatabaseServiceProvider.php line 88:
                                   
  Class 'Faker\Factory' not found  
                                   

Cleaning up file based variables
ERROR: Job failed: command terminated with exit code 1

2、在本地环境搜索 Class ‘Faker\Factory’,确定 /vendor/fzaninotto/faker/src/Faker/Factory.php 是存在的。在本地环境执行:php artisan key:generate 成功。如图2

图2

PS E:\wwwroot\object> php artisan key:generate
Application key set successfully.

3、查看 gitlab-runner 中的日志,if [ ! -x “vendor” ];then echo ‘vendor not exists’; composer self-update 2.1.14; composer install –prefer-dist –no-ansi –no-interaction –no-progress –no-scripts –no-dev; else echo ‘vendor exists’; fi。如图3

图3

$ if [ ! -x "vendor" ];then echo 'vendor not exists'; composer self-update 2.1.14; composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-scripts --no-dev; else echo 'vendor exists'; fi
vendor not exists
You are already using the latest available Composer version 2.1.14 (stable channel).
Installing dependencies from lock file
Verifying lock file contents can be installed on current platform.
Package operations: 233 installs, 0 updates, 0 removals

4、在本地环境执行 composer install –prefer-dist –no-ansi –no-interaction –no-progress –no-scripts –no-dev,然后再执行 php artisan key:generate。报错:In Application.php line 679: Class ‘Barryvdh\Debugbar\ServiceProvider’ not found。原因应该在于本地环境与线上环境的配置项有差异。

PS E:\wwwroot\object> php artisan key:generate

In Application.php line 679:

  Class 'Barryvdh\Debugbar\ServiceProvider' not found


5、在本地环境执行 composer install –prefer-dist –no-ansi –no-interaction –no-progress –no-scripts,然后再执行 php artisan key:generate。不再报错。由此确认原因在于 –no-dev 的添加导致了流水线失败。–no-dev: 跳过 require-dev 字段中列出的包。在 composer.json 的 require-dev 配置中,存在 “fzaninotto/faker”: “^1.4″。

    "require-dev": {
        "fzaninotto/faker": "^1.4",
    },

6、将 require-dev 配置中的 “fzaninotto/faker”: “^1.4” 移至 require 配置中。不再报错。

永夜