All Products
Search
Document Center

Alibaba Cloud DevOps:Java test build

Last Updated:Apr 23, 2025

Flow provides an end-to-end Java project test and build solution. Flow helps you efficiently configure continuous integration or continuous delivery (CI/CD) pipelines and automates testing, code compilation, dependency management, and build artifact upload. This topic describes how to configure the Java · Test, build pipeline in the Flow console.

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 the Java · Test, build template and click Create.

    image

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 JAVA as Code Type, and click Add.

Step 3: Configure the test build

The Java · Test, build template includes the preset Java Code Scan, Maven Unit Testing, and Java Build Upload jobs. Those jobs have similar configurations. This step describes how to configure the Java Build Upload job.

image

Configure the Java Build Upload job

  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.

    Specify Container Environment/Default VM Environment

    1. Install Java

      Specify JDK Version and Maven Version.

      image

    2. Execute Commands

      Specify a custom build command. Multiple Maven versions are supported. The command execution directory is the root path of the code repository.

      image

    3. Artifact Upload

      Upload build artifacts to Artifact Repository 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 Service Connection Management.

      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

    Parameters of the Java Code Scan job

    Parameter

    Description

    Enable Incremental Scan Mode

    If this option is not selected, a full code scan will be performed.

    Use a Custom-Rule Directory

    If this option is selected, the p3c rule file in your code repository is used. You can configure a custom rule directory.

    Rule Set

    If Use a Custom-Rule Directory is not selected, the default rule is used.

    SubDirectory

    The directory where the code to be scanned resides. If you do not specify this parameter, the root path of the code repository is used by default.

    SubDirectory to be Excluded

    The directory or file to be excluded from the scan scope. You can refer to the gitignore configuration. For example, if you set the value to test/, all files in the test/ directory are not scanned.

    Redline Information

    Determine whether code scan is successful. The following dimensions can be set:

    • Total Issues

    • Bloker Issues

    • Critical Issues

    • Major Issues

    Parameters of the Maven Unit Testing job

    Parameter

    Description

    Execute Commands

    Specify custom commands for Maven unit testing.

    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: target/site/surefire-report.html.

    Reporter

    Select a testing tool or framework. Example: Java-JUnit.

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.

    image

  2. After the pipeline job is complete, runtime logs are generated in each job node. Click Logs in each job node to view the related logs. For example, view Java Build Upload logs.

    image