在 jenkins 容器中安装 php 和 composer

install php and composer inside jenkins container

我正在尝试创建一个具有 'Test' 阶段的 Jenkins 管道,该阶段需要 PHP 和 Composer,以便 运行 使用 PHPUnit 进行测试。

如何在 Jenkins Docker 容器中安装 PHP(最好是版本 7.4)和 Composer?

这是我在容器的 Docker 文件中尝试的方式:

FROM jenkins/jenkins

USER root

# install PHP and Composer
RUN apt-get install -y php php-mbstring php-xml php-bcmath && \
    apt-get install -y composer
    
USER jenkins

当我构建图像时出现此错误:

Step 3/4 : RUN apt-get install -y php php-mbstring php-xml php-bcmath php-fpm &&     apt-get install -y composer && apt-get install -y vim
 ---> Running in 0b20c56bd720
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package php
E: Unable to locate package php-mbstring
E: Unable to locate package php-xml
E: Unable to locate package php-bcmath
E: Unable to locate package php-fpm

您在 install 之前错过了 apt-get update

The sudo apt-get update command is used to download package information from all configured sources

参见this