All Products
Search
Document Center

Alibaba Cloud DevOps:Java test and build

Last Updated:Jun 22, 2026

Flow provides an end-to-end solution for testing, building, and uploading build artifacts for Java projects. You can quickly set up a CI/CD pipeline to automate testing, code compilation, dependency management, and artifact uploads by using the Java · Test, Build template in the visual editor.

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. In the Select a pipeline template dialog box, select Java · Test, Build, and click Create.

Step 2: Configure the pipeline source

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

  2. Add a code source. This example uses the preset Sample Code Source for Java provided by Alibaba Cloud DevOps. Click Add.

Step 3: Configure test and build jobs

The Java · Test, Build template includes three predefined jobs: Java Code Scan, Maven Unit Testing, and Java Build Upload. Their configurations are similar. This section uses the Java Build Upload job as an example. On the Process Configuration tab, click the Java Build Upload job in the Build stage to open its configuration panel.

Java build upload

  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.

    Container and VM environment

    1. Install Java

      Select the required JDK Version and Maven Version. For example, you might set Step Name to Install Java, JDK Version to JDK 1.8, and Maven Version to Maven 3.5.2.

    2. Execute Command

      Enter custom build commands. Multiple versions of Maven are supported. These commands are executed in the root directory of the code repository.

      For example, enter the build command mvn -B clean package -Dmaven.test.skip=true -Dautoconfig.skip. Below the command field, you can choose whether to Specify Shell and add custom environment variables in the Environment Variables section.

    3. Upload Artifact

      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.

Java code scan parameters

Parameter

Description

Enable Incremental Scan Mode

If this option is not enabled, a full code scan is performed.

Use Custom Rule Directory

If enabled, Flow uses the p3c rule file in your code repository. You can configure a custom rule directory.

Rule Set

If Use Custom Rule Directory is not enabled, the default rule set is used.

Subdirectory

The directory containing the code to be scanned. If not specified, the scan runs on the root of the code repository.

Exclude Subdirectory

The directories or files to exclude from the scan. The format is similar to a .gitignore file. For example, entering test/ excludes all files in the test/ directory from the scan.

Redline Information

Define the success criteria for the code scan based on the following four metrics:

  • Total Issues

  • Blocker Issues

  • Critical Issues

  • Major Issues

Maven unit testing parameters

Parameter

Description

Execute Command

Specify custom Maven unit testing commands.

Test report path

The path to the test report file. This must point to a file. The entire directory containing this file is uploaded. For example, target/site/surefire-report.html.

Testing tool

Select a testing tool or framework, such as Java-JUnit.

Step 4: Run the pipeline and view the results

  1. After finishing the configuration, click Save and Run in the upper-right corner. In the dialog box, click Run to start the pipeline. The visual editor displays the execution progress of each stage: the Pipeline Source stage pulls the code repository first, then the Java Code Scan and Maven Unit Testing jobs run in parallel in the Test stage, and finally the Java Build Upload job in the Build stage begins.

  2. After a pipeline run completes, each job generates a log. Click Logs on a job's node to view the details. The following is an example log for the Java Build Upload job:

    [executionStep begins at 2025-03-25 13:30:45]
    ######################################################
    # name      : ArtifactUpload
    # version   : v1.3.91
    # description : artifact upload
    # help url  : https://atomgit.com/flow-step/ArtifactUpload.git
    # build id  : e819a91f-8d7c-4e2d-9bfa-658f7fd89f64
    ######################################################
    2025-03-25 13:30:45 [INFO] Start to pack artifact
    2025-03-25 13:30:45 [INFO] PackInputs, {"projectDir":"/root/workspace/__flow_work/__flow_builds/f8f02d6c-a8fb-41eb-a9a2-e8284ed5240c/workspace/spring-boot_cmBM","sourcePath":
    ["target"],"filePath":"target","gitIgnore":"false","includePathInArtifact":"false","artifactFullName":"/root/workspace/__flow_work/__flow_builds/f8f02d6c-a8fb-41eb-a9a2-e8284ed5240c/workspace/packages/Artifacts_4032193.tgz"}
    2025-03-25 13:30:45 [INFO] Pack single file without file path
    2025-03-25 13:30:46 [INFO] use oss endpoint:xxx.aliyuncs.com
    It's recommended to set 'refreshSTSToken' and 'refreshSTSTokenInterval' to refresh stsToken、accessKeyId、accessKeySecret automatically when sts token has expired
    2025-03-25 13:30:46 [INFO] Artifact download URL is: http://xxx oss-cn-beijing-internal.aliyuncs.com/xxx/Artifacts_4032193.tgz
    2025-03-25 13:30:46 [INFO] run step successfully!