All Products
Search
Document Center

Alibaba Cloud DevOps:Node.js test build

Last Updated:May 15, 2025

Flow provides an end-to-end Node.js 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 Node.js · 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 Node.js · 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 NodeJS as Code Type, and click Add.

Step 3: Configure the test build

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

Configure the Node.js Build 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.

    Specified Container Environment/Default VM Environment

    1. Setup Node Environment

      Configure parameters including Node Version and Npm Type.

      Important

      You can select Choose from Pre-set Version, Enter a Specified Version, or ...specified in the '.nvmrc' file in the code repository from the Version Source drop-down list. However, if a .nvmrc file exists, the .nvmrc file is used, regardless of which option is selected.

      image

    2. Execute Commands

      Specify custom build commands to be executed and select Use Specific Shell. If required, configure environment variables by referring to Environment variables.

      image

    3. Artifact Upload

      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

Parameters of the JavaScript Code Scan job

Parameter

Description

Use local ESLint configuration

Specifies whether to use the local ESLint configuration instead of the system rule set for scanning. After you enable this option, you must specify the required dependencies for the Dependencies Required to Run a Local ESLint Configuration parameter and make that an .eslintrc.* file exists in the repository root directory.

Dependencies Required to Run a Local ESLint Configuration

The dependencies that are required to run a local ESLint configuration. Separate multiple dependencies with spaces. This parameter is specified after npm install. For example, if you use eslint-config-standard, you must set this parameter to eslint eslint-config-standard, eslint-plugin-standard, eslint-plugin-promise, eslint-plugin-import, and eslint-plugin-node. If this parameter is set to *, all the dependencies that are declared in the package.json file are installed by default.

Important

This parameter is valid only if the Use local ESLint configuration option is selected.

Enable incremental scan mode

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

Subdirectories 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 Node.js Unit Testing job

Parameter

Description

Execute Commands

Specify custom commands for Node.js unit testing.

Path of Test Report

The path of test reports generated after test commands are executed. Example: mochawesome-report/mochawesome.html.

Reporter

Select a testing tool or framework. Example: Node.js-Mocha.

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