All Products
Search
Document Center

Alibaba Cloud DevOps:PHP test and build

Last Updated:Jun 22, 2026

A PHP test and build pipeline automates code checkout, compilation, unit testing, and result logging to reduce manual work and help developers identify and resolve issues faster.

Step 1: Create a test and build pipeline

  1. Log on to the Alibaba Cloud DevOps console and click Create Pipeline in the upper-right corner.

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

Step 2: Configure the pipeline source

  1. In the Pipeline Source stage, click Add Pipeline Source.

  2. Select Sample Code Source. For Code Type, select PHP, and then click Add.

Step 3: Configure testing and build

In the Test stage, select a build cluster and build environment to run build jobs.

  1. Configure the basic parameters.

    Parameter

    Description

    Job Name

    Enter a custom name for the job, or use the default.

    Build Cluster

    The following build clusters are supported:

    Build Environment

    The following build environments are supported:

    • Specify Container Environment (for Alibaba Cloud DevOps default build cluster): Flow starts a specified container on the build machine and performs the build in that single-container environment. Alibaba Cloud DevOps provides a list of official images. You can also specify your own image as the runtime environment.

    • Default VM Environment (supported only for private build clusters): You must select Specify Build Nodes. Flow installs the environment and runs the job directly on the build machine. To speed up the job, we recommend installing the required SDKs and environment on the build machine in advance.

    Note

    During job execution, you have full control over the build environment and the job execution script.

    Download Pipeline Source

    If enabled, the configured code source is downloaded to the corresponding working directory. The available options are:

    • Download All Pipeline Sources

    • Do Not Download Pipeline Sources

    • Download Selected Pipeline Sources

  2. Configure the task steps.

    Specified container and default VM

    Unit testing

    1. In an Empty Job > New Stage, click Add Step and select Build > Execute Commands to configure the execution commands.

    2. Then, click Add Step again and select Test > Unit Test Report to configure the unit test report parameters.

    Parameter

    Description

    Step name

    A custom name for the step.

    Container image address

    The full container image address. This parameter is required only for the Specify container environment option.

    Provide the full image address, for example, 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, commands may fail.

    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 "=================="

    Test report file path

    Path to the test report file. The directory containing this file is uploaded. Example: report/index.html.

    Testing tool

    The testing tool or framework. Select Php-UnitTest.

    Stop pipeline on test failure

    If enabled, the pipeline stops when a unit test fails. Default: Enabled.

    PHP build

    In the PHP Build stage, select a build environment based on the selected build cluster to run the build job.

    1. Configure build environment parameters and related commands.

      Parameter

      Description

      Container image address

      Provide the full image address, for example, build-steps-public-registry.<region_ID>.cr.aliyuncs.com/build-steps/alinux3:latest. This parameter is required only for the Specify container environment option.

      Use private image repository

      Add a service connection. For more information, see Manage service connections. Required only for the Specify container environment option.

      Download pipeline source

      When enabled, the pipeline downloads your configured source files to the working directory.

      Execute commands

      The default command for PHP is php --version.

    2. In the Upload Artifact task step, configure the Upload Method and related parameters.

      Upload to Packages

      Parameters:

      Parameter

      Description

      Add Service Connection

      Click Add Service Connection and follow the prompts to create a service connection from Flow to Packages. For more information, see Manage service connections.

      Repository

      After you add the service connection, you can select a Generic Artifacts repository in Packages as the target repository.

      Note

      For more information about Generic Artifacts repositories, see Manage generic artifacts.

      Artifact Name

      Distinguishes artifacts from different builds and is used by deployment components. We recommend using dynamic variables. The default is Artifacts_${PIPELINE_ID}. You can specify a custom name such as target1.

      Artifact Version

      The version uniquely identifies your artifact. Duplicate versions of the same artifact cannot be pushed. We recommend using a dynamic variable such as ${DATETIME}.

      Packaging Path

      Specify the relative path to the project's root directory, such as target/. You can specify multiple paths.

      Include packaging path in artifact

      If this option is selected, the generated archive includes the full packaging path. Otherwise, it only includes the files. If you specify multiple paths for Packaging Path, this option is automatically enabled.

    Host deployment

    In the Host Deployment stage, deploy the artifact from the PHP build stage to hosts in a host group. For more information, see Host deployment.

    Set Host group to go-test-env, Download path to /home/admin/app/package.tgz, and Execution user to root. In the deployment script, add the decompression command tar zxvf /home/admin/app/package.tgz -C /home/admin.

Step 4: Run and view the pipeline job

  1. After configuring the pipeline, click Save and Run in the upper-right corner. In the dialog box that opens, click Run to start the pipeline.

  2. After the pipeline job is complete, click Logs at the bottom right of the job node to view the execution logs. A successful pipeline run completes three stages: PHP unit test (5 of 5 test cases passed, 100% pass rate), PHP build (generates the build artifact), and Host deployment. The total runtime is about 1 minute and 41 seconds.