首页 > 解决方案 > Gitlab CI 和 php 版本

问题描述

我有.gitlab-ci.yml。这里我们刚刚安装了composer。composer.json 需要 php 7.4。

image: php:7.4
stages: # List of stages for jobs, and their order of execution
  - test

before_script:
  # Install composer dependencies
  - wget https://composer.github.io/installer.sig -O - -q | tr -d '\n' > installer.sig
  - php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  - php -r "if (hash_file('SHA384', 'composer-setup.php') === file_get_contents('installer.sig')) { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
  - php composer-setup.php
  - php -r "unlink('composer-setup.php'); unlink('installer.sig');"


unit_test:
  stage: test
  script:
    - php composer.phar install
    - phpunit --configuration phpunit.xml

然后我跑

gitlab-runner exec shell unit_test

在我的本地机器(macos)上并获得:

  Problem 1
    - Root composer.json requires php ~7.4 but your php version (7.3.29) does not satisfy that requirement.

为什么?为什么是 7.3.29?此外,“图像”设置似乎忽略了版本

标签: phpgitlabgitlab-cigitlab-ci-runner

解决方案


您必须更新您的项目 composer.json :找到“require”行,它告诉您的项目您需要哪个版本的库

"require": {
    "php": "^7.4|^8.0",
},

编辑:如果你需要 7.4 那么你必须在你的 composer.json 中这样写

"require": {
    "php": "7.4",
},

解决方案与您使用的版本无关,这是因为您的项目配置(在 composer.json 中)不好


推荐阅读