Registry / devops / build-number

build-number

JSON →
library1.0.0jsnpmunverified

The `build-number` package offers a focused utility for programmatically detecting the current build or run number within various Continuous Integration (CI) environments. It simplifies the process of retrieving this critical metadata by abstracting away the platform-specific environment variables used by systems such as GitHub Actions, GitLab CI, Travis CI, Jenkins, and others. The current stable version is 1.0.0, suggesting a foundational and robust release. Given its specific utility, the package likely follows a maintenance-oriented release cadence, with updates primarily driven by changes in CI platform environment variables or the introduction of new CI systems. Its key differentiator is its singular focus on providing a consistent API for build number retrieval, aiming to reduce boilerplate and ensure portability across different CI/CD pipelines without requiring developers to manually parse or conditionally check numerous environment variables.

npm install build-number
INSTALL
IMPORT
SIG · BUILD-NUMBER
B
build-number
devopsjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getBuildNumber
const getBuildNumber = require('build-number');
const buildNumber = require('build-number'); const result = buildNumber.getBuildNumber();
The package exports the detection function directly as the CommonJS module.exports.
getBuildNumber
import getBuildNumber from 'build-number';
import { getBuildNumber } from 'build-number';
As a direct CommonJS export, it translates to a default import in ESM. Named imports will not work.
getBuildNumber
import getBuildNumber from 'build-number';
import * as buildNumber from 'build-number'; const result = buildNumber.default();
While `buildNumber.default()` might technically work in some environments, it's not the idiomatic way to import a default export.

Demonstrates how to import and use the `getBuildNumber` function, logging the detected build number or a warning if none is found.

import getBuildNumber from 'build-number'; function getAndLogBuildNumber() { // Simulate a CI environment variable if not running in actual CI // For example, on GitHub Actions, GITHUB_RUN_NUMBER would be set. // process.env.GITHUB_RUN_NUMBER = '12345'; // Uncomment for testing outside CI const buildNumber = getBuildNumber(); if (buildNumber) { console.log(`Detected CI Build Number: ${buildNumber}`); // Example usage: Update a version string, tag a release, etc. // const version = `1.0.0-build.${buildNumber}`; // console.log(`Full version string: ${version}`); } else { console.warn('No CI build number detected. This might be expected outside a CI environment.'); } } getAndLogBuildNumber();
Debug
Known issues
gotchaThe `getBuildNumber()` function will return `null` or `undefined` (depending on the environment) if it's not run within a recognized CI environment. This is expected behavior and not an error.
fix
Always check for a non-null/non-undefined return value before using the build number, especially in local development or non-CI contexts.
affects: >=1.0.0
gotchaThis package relies on specific environment variables set by CI providers. If your CI pipeline customizes these variables or runs in an unrecognized environment, the detection might fail or return incorrect values.
fix
Consult the `build-number` source code or documentation (if available) to understand which environment variables are checked for your specific CI provider. Ensure your CI configuration sets these variables correctly.
affects: >=1.0.0
gotchaThe `1.0.0` version of `build-number` is primarily a CommonJS module. While it can be imported in ESM projects using `import getBuildNumber from 'build-number';`, using named imports like `import { getBuildNumber } from 'build-number';` will result in an error.
fix
For ESM, always use `import getBuildNumber from 'build-number';`. For CommonJS, use `const getBuildNumber = require('build-number');`.
affects: 1.0.0
Errors
Common errors & fixes
TypeError: buildNumber is not a function
Attempting to call `buildNumber()` directly after importing with `import * as buildNumber from 'build-number';` in ESM or `const buildNumber = require('build-number');` and then trying `buildNumber.getBuildNumber()` in CJS. The package directly exports the function.
fix
For CommonJS: `const getBuildNumber = require('build-number');`. For ESM: `import getBuildNumber from 'build-number';`.
SyntaxError: Cannot use import statement outside a module
Using `import getBuildNumber from 'build-number';` in a Node.js environment configured for CommonJS (e.g., without `"type": "module"` in `package.json` or a `.mjs` extension).
fix
Either convert your project to ESM (add `"type": "module"` to `package.json` or use `.mjs` files) or use the CommonJS `require` syntax: `const getBuildNumber = require('build-number');`.
My script logs 'No CI build number detected' even though I'm in CI!
The package couldn't identify your CI environment. This could be due to an unsupported CI platform, non-standard environment variables, or a missing `.env` file if used locally.
fix
Verify that your CI platform is supported by `build-number`. Check your CI environment variables to ensure they match what the package expects (e.g., `GITHUB_RUN_NUMBER`, `CI_COMMIT_PIPELINE_ID`). If running locally, ensure relevant environment variables are set before execution.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
build-number — npm install build-number · libregistry