Browse documentation

Build a Node.js project

This tutorial creates a small Node.js project, pushes it to a Git repository hosted by Codinamo, and builds it with Git Clone, npm, and Test Report actions.

The pipeline graph is:

clone -> install -> test -> tests -> build

Create the Node.js project

The example has no dependencies. It uses the test runner built into Node.js, which can write the JUnit XML that the Test Report action reads.

package.json
{
  "name": "hello-node",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --test --test-reporter=spec --test-reporter-destination=stdout --test-reporter=junit --test-reporter-destination=junit.xml",
    "build": "node scripts/build.js"
  }
}
src/greeting.js
export function greeting(name) {
    return `Hello, ${name}!`;
}
test/greeting.test.js
import assert from "node:assert/strict";
import { describe, it } from "node:test";

import { greeting } from "../src/greeting.js";

describe("greeting", () => {
    it("greets by name", () => {
        assert.equal(greeting("Codinamo"), "Hello, Codinamo!");
    });
});
scripts/build.js
import { cpSync, mkdirSync, rmSync } from "node:fs";

rmSync("dist", { recursive: true, force: true });
mkdirSync("dist");
cpSync("src", "dist", { recursive: true });
console.log("Build written to dist/");

Generate the lock file and check the project locally:

npm install
npm test
npm run build

npm install creates package-lock.json. Commit it: npm ci installs exactly what the lock file describes and fails when the file is missing.

Keep the tests inside a describe block. Test Report counts the test cases of each JUnit suite, and the Node.js reporter writes one suite per describe.

Add node_modules/, dist/, and junit.xml to .gitignore.

Create the Codinamo project and push the code

  1. Open Projects and select Create new.

  2. Enter hello-node as the name, turn on Enable Git repository, and select Create.

  3. Open the project’s Source tab and copy the repository URL.

  4. Push the project:

    git init -b main
    git add .
    git commit -m "Initial commit"
    git remote add origin https://git.codinamo.com/OWNER/hello-node.git
    git push -u origin main

Replace the URL with the one shown in the application. Git asks for your Codinamo credentials. See Hosted Git repositories.

Store the clone credential

The hosted repository is private, so the pipeline needs credentials to clone it.

  1. Open Secrets and create a secret group.

  2. Add a secret named GIT_PASSWORD with the password of the account that clones the repository.

  3. Save the group.

The pipeline refers to the value as ${GIT_PASSWORD}; the password itself never appears in the pipeline source. See Secrets.

If your repository is public, skip this section and leave username and password out of the clone action.

Create the pipeline

  1. Open Pipelines and select Create new.

  2. Select the hello-node project, enter node-build as the name, and select Create.

  3. On the pipeline page, select the secret group that holds GIT_PASSWORD.

  4. Select Edit flow.

Add the actions

Add and configure these actions on the Visual tab, or paste the source from the next section into the ICE tab.

Reference name Action Configuration

clone

Git Clone

Repository: the repository URL; Directory: source; Branch: main; Username: your handle; Password: ${GIT_PASSWORD}

install

npm

Command: ci; Node Version: 22; Working Directory: source

test

npm

Command: test; Node Version: 22; Working Directory: source

tests

Test Report

Report files: source/junit.xml; Format: JUNIT

build

npm

Command: run; Arguments: build; Node Version: 22; Working Directory: source

Connect the actions in the order shown at the top of this page.

The npm action runs npm, followed by Command and then Arguments, in the working directory. run with the argument build therefore executes npm run build.

Node Version accepts 18, 20, or 22 and defaults to 20. Set the same version on every npm action so the install, test, and build steps use the same runtime. The example was checked with Node.js 22; if you select another version, confirm that it supports the junit test reporter.

Report file patterns are relative to the run workspace, which is why the path starts with the clone directory.

Complete pipeline.ice

ICE-1.0.0
codinamo >= 1.0.0

@pipeline {
    name: "node-build"
    description: "Build hello-node"
    environment: "default"
    continueOnError: false

    @triggers {
        manual: {}
    }

    @actions {
        clone: action.GIT_CLONE({
            params: {
                repositoryUrl: "https://git.codinamo.com/OWNER/hello-node.git",
                targetDirectory: "source",
                branch: "main",
                username: "YOUR_HANDLE",
                password: "${GIT_PASSWORD}"
            }
        })
        install: action.NPM({
            params: {
                command: "ci",
                nodeVersion: "22",
                workingDirectory: "source"
            }
        })
        test: action.NPM({
            params: {
                command: "test",
                nodeVersion: "22",
                workingDirectory: "source"
            }
        })
        tests: action.TEST_REPORT({
            params: {
                allowEmpty: false,
                failOnFailure: true,
                format: "JUNIT",
                reports: "source/junit.xml"
            }
        })
        build: action.NPM({
            params: {
                command: "run",
                args: "build",
                nodeVersion: "22",
                workingDirectory: "source"
            }
        })
    }

    @flow {
        clone -> install -> test -> tests -> build
    }
}

Replace OWNER and YOUR_HANDLE with your own values.

Instead of repeating the directory name, later actions can read it from the clone action with workingDirectory: "${clone.repository_path}".

Run and inspect

  1. Select Commit in the editor, enter a commit message, and confirm.

  2. Return to the pipeline page and select Run pipeline.

  3. Open the run.

  4. Confirm that all five steps succeeded.

  5. Read the test report for the test counts and duration, and expand the logs of any failed action.

How to read a failure:

  • install fails when package-lock.json is missing or does not match package.json.

  • test fails when a test fails, because npm test exits with an error. With continueOnError: false the run stops there and the later steps do not run; the failing test is in the log of the test action.

  • tests fails when no file matches the report pattern, or when the report contains failures or errors.

The clone.commit_sha and clone.branch outputs, and the tests.test_count, tests.failure_count, tests.error_count, tests.skipped_count, and tests.duration_seconds outputs, are available to later actions.

Other Node.js actions

Node

Runs a script with node. Parameters: scriptPath (required), nodeVersion, workingDirectory, nodeArgs, and args.

npx

Runs a package with npx. Parameters: package (required), nodeVersion, workingDirectory, and args.

For example, the build step can call the script directly:

build: action.NODE({
    params: {
        scriptPath: "scripts/build.js",
        nodeVersion: "22",
        workingDirectory: "source"
    }
})

Python projects

The same shape works for Python with the pip and Python actions: clone, install the requirements, then run a script.

@actions {
    clone: action.GIT_CLONE({
        params: {
            repositoryUrl: "https://example.com/team/application.git",
            targetDirectory: "source"
        }
    })
    install: action.PIP({
        params: {
            command: "install",
            args: "-r requirements.txt",
            workingDirectory: "source"
        }
    })
    run: action.PYTHON({
        params: {
            scriptPath: "main.py",
            pythonVersion: "3",
            workingDirectory: "source"
        }
    })
}

@flow {
    clone -> install -> run
}

pip runs pip3, followed by command and then args. Python also accepts pythonArgs for interpreter options and args for script arguments; pythonVersion is 2 or 3 and defaults to 3.

Next steps