Gitlab CI 和 php 版本

问题描述 投票:0回答:2

我有 .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? 此外,看起来“图像”设置忽略了版本

php gitlab gitlab-ci gitlab-ci-runner
2个回答
0
投票

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

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

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

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

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


0
投票

这已经很旧了,但是那些人仍然来这里寻找解决方案:主要问题是,如果安装了多个版本,composer 就会采用另一个 php 版本。更多信息可以在这个StackOverflow问题中找到。

© www.soinside.com 2019 - 2024. All rights reserved.