【问题标题】:Gitlab CI and php verstionGitlab CI 和 php 版本
【发布时间】:2021-12-12 14:33:29
【问题描述】:

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

【问题讨论】:

  • 你能抓住你的 CLI 并测试你的 Php 版本吗? php -v错误告诉你Composer需要更新版本的php
  • 本地安装:php -v PHP 7.4.24 (cli) (built: Oct 12 2021 21:08:53) (NTS) 版权所有 (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies 与 Zend OPcache v7.4.24,版权所有 (c),由 Zend Technologies 提供
  • 在终端检查你的php版本 php -v 并更新终端的php版本。

标签: php gitlab gitlab-ci gitlab-ci-runner


【解决方案1】:

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

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

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

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

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

【讨论】:

  • 我正好需要 7.4。为什么 8.0 会解决这个问题?
  • 我编辑了我的答案,请将要求添加到您的 composer.json 并重新构建您的项目
猜你喜欢
  • 2019-07-28
  • 2020-09-09
  • 2020-05-23
  • 1970-01-01
  • 2019-09-26
  • 2021-04-28
  • 2019-02-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多