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.
{
"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"
}
}
export function greeting(name) {
return `Hello, ${name}!`;
}
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!");
});
});
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
-
Open Projects and select Create new.
-
Enter
hello-nodeas the name, turn on Enable Git repository, and select Create. -
Open the project’s Source tab and copy the repository URL.
-
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.
-
Open Secrets and create a secret group.
-
Add a secret named
GIT_PASSWORDwith the password of the account that clones the repository. -
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
-
Open Pipelines and select Create new.
-
Select the
hello-nodeproject, enternode-buildas the name, and select Create. -
On the pipeline page, select the secret group that holds
GIT_PASSWORD. -
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 |
|---|---|---|
|
Git Clone |
Repository: the repository URL; Directory: |
|
npm |
Command: |
|
npm |
Command: |
|
Test Report |
Report files: |
|
npm |
Command: |
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
-
Select Commit in the editor, enter a commit message, and confirm.
-
Return to the pipeline page and select Run pipeline.
-
Open the run.
-
Confirm that all five steps succeeded.
-
Read the test report for the test counts and duration, and expand the logs of any failed action.
How to read a failure:
-
installfails whenpackage-lock.jsonis missing or does not matchpackage.json. -
testfails when a test fails, becausenpm testexits with an error. WithcontinueOnError: falsethe run stops there and the later steps do not run; the failing test is in the log of thetestaction. -
testsfails 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, andargs. - npx
-
Runs a package with
npx. Parameters:package(required),nodeVersion,workingDirectory, andargs.
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
-
Variables and action outputs explains how to pass values between actions.
-
Secrets covers secret groups and log protection.
-
Runs and logs describes the run page.
-
Action catalog lists every action with its parameters and outputs.