All Products
Search
Document Center

Alibaba Cloud DevOps:PHP test build

Last Updated:May 15, 2025

The PHP test build pipeline automates code checkout, compilation and build, unit testing, result recording, and test statistics collection. This minimizes manual intervention, improves project visibility, and enables developers to easily identify and resolve issues based on valid logs.

Step 1: Create a test build pipeline

  1. Log on to the Flow console. In the console, click Create Pipeline in the upper-right corner.

  2. In the Select a pipeline template dialog box, select PHP · Build, deploy to Alibaba Cloud ECS/self-hosted server and click Create.

    ca2ea3b5bec2121dafa02ebf5c2bc09f

Step 2: Configure a pipeline source

  1. On the Process Configuration page of the new pipeline, click Add Pipeline Source in Pipeline Source.

  2. Click Code Source. In this topic, select Sample Code Source, select PHP as Code Type, and click Add.

Step 3: Configure the test build

The pipeline allows you to specify different values for Build Cluster and Build Environment in different Test stages to perform build jobs.

  1. Configure basic parameters.

    Parameter

    Description

    Job Name

    You can specify a job name or use the default name.

    Build Cluster

    The following build clusters are supported:

    Build Environment

    The following build environments are supported:

    • Specify Container Environment (default build cluster provided by Alibaba Cloud DevOps): Flow starts the specified container on the build machine and builds a single-container environment. Alibaba Cloud DevOps provides Flow System Images. You can also specify your image as the build environment.

    • Default VM Environment (supported only by self-hosted build clusters): You must select a value from the Specify Build Nodes drop-down list. Flow directly installs the environment on the build machine and runs the job. To increase job build efficiency, we recommend that you install the related SDK and environment on the build machine in advance.

    Note

    During job execution, the pipeline job build environment is assigned to you. You have the permissions to use the build environment and can create a custom job execution script.

    Download Source

    The configured source file can be downloaded to the corresponding working directory. The following three download methods are available:

    • Download All Pipeline Sources

    • Do Not Download Pipeline Sources

    • Download Selected Pipeline Sources

  2. Configure build steps.

    Specified Container Environment/Default VM Environment

    Unit Testing

    1. Click Add New Stage. Then, click Empty Job in Empty Template. Click the Empty Job node. In the Edit panel, click Add Step in the Build Steps section, and choose Build > Execute Commands. Configure the commands to be executed.

    2. Click Add Step and choose Test > Unit Test Report. Configure parameters of Unit Test Report.

    Parameter

    Description

    Step Name

    Specify a step name.

    Container Image

    Enter a container image URL. This parameter is valid only for Specify Container Environment.

    Provide a complete container image URL in the following format: build-steps-public-registry.ap-southeast-1.cr.aliyuncs.com/build-steps/php:version number.

    Execute Commands

    Specify the correct PHP version in your code repository. Otherwise, an error may occur when commands are run.

    mkdir report
    php --version
    
    curl -sS https://getcomposer.org/installer | php
    mv composer.phar /usr/local/bin/composer
    composer -v
    composer install
    composer require --dev phpunit/phpunit:^10
    vendor/bin/phpunit --testdox-html ${PROJECT_DIR}/report/index.html
    echo "=================="
    cat report/index.html
    echo "=================="

    Path of Test Report

    The path of test reports. The path must point to a file, and all files in the directory where the file exists are uploaded. Example: report/index.html.

    Reporter

    Select a testing tool or framework. Example: Php-UnitTest.

    Fail on Error

    Specifies whether to stop the pipeline when a unit test fails. The check box is selected by default.

    高的 - 2025-04-09T132453

    PHP BUILD

    In the PHP BUILD stage, you can select different values from the Build Environment drop-down list based on the values of Build Cluster to perform the build job.

    1. Configure build environment parameters and related commands to be executed.

      Parameter

      Description

      Container Image

      Provide a complete container image URL in the following format: build-steps-public-registry.xxx.cr.aliyuncs.com/build-steps/alinux3:latest. This parameter is valid only for Specify Container Environment.

      Use Private Image Repository

      Add a service connection. For more information, see Manage service connection. This parameter is valid only for Specify Container Environment.

      Download Source

      The configured source file can be downloaded to the corresponding working directory.

      Commands to Execute

      The default command to be executed for PHP is php --version.

      image

    2. In the Artifact Upload job step, configure Upload Type and related parameters.

      Upload build artifacts to Packages for centralized management

      Parameter description:

      Parameter

      Description

      Add a service connection

      Click Add a service connection. Create a service connection from Flow to Alibaba Cloud DevOps Packages. For more information, see Manage service connection.

      Repository

      After a service connection is added, select the Generic repositor type in Packages.

      Note

      For more information about Generic repositories, see Generic artifact management.

      Artifact Name

      This parameter is used to distinguish between different artifacts generated by multiple builds. The artifact name is used in component deployment. We recommend that you specify the name by using a dynamic variable. Artifacts_${PIPELINE_ID} is used by default. You can also specify an artifact name, such as target1.

      Product version

      Uniquely identifies your artifact file. Repeated versions are not allowed for the same file. We recommend that you specify the name by using a dynamic variable. Example: ${DATETIME}.

      Package Path

      Set the starting position as the relative path of the project folder. Example: target/. You can set multiple file paths.

      The directory containing the package path in the product

      If this option is selected, the generated package contains the complete packaging path. Otherwise, the package contains only files. When multiple packaging paths are set, this option is selected automatically.

      Configuration example:

      image

    Host Deployment

    In the Host Deployment stage, you can deploy the artifacts produced in the PHP BUILD stage to the hosts in a host group. For more information about the parameters, see Host deployment.

    高的 (80)

Step 4: Run and view a pipeline job

  1. After the process configuration is complete, click Save and Run in the upper-right corner. In the dialog box that appears, click Run to run the pipeline job.

  2. After the pipeline job is complete, in the build image job node, click Logs in the lower right part to view the execution process and result logs of the pipeline job.image