{"id":12923,"library":"build-number","title":"CI Build Number Detector","description":"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.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/nkt/build-number","tags":["javascript"],"install":[{"cmd":"npm install build-number","lang":"bash","label":"npm"},{"cmd":"yarn add build-number","lang":"bash","label":"yarn"},{"cmd":"pnpm add build-number","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports the detection function directly as the CommonJS module.exports.","wrong":"const buildNumber = require('build-number'); const result = buildNumber.getBuildNumber();","symbol":"getBuildNumber","correct":"const getBuildNumber = require('build-number');"},{"note":"As a direct CommonJS export, it translates to a default import in ESM. Named imports will not work.","wrong":"import { getBuildNumber } from 'build-number';","symbol":"getBuildNumber","correct":"import getBuildNumber from 'build-number';"},{"note":"While `buildNumber.default()` might technically work in some environments, it's not the idiomatic way to import a default export.","wrong":"import * as buildNumber from 'build-number'; const result = buildNumber.default();","symbol":"getBuildNumber","correct":"import getBuildNumber from 'build-number';"}],"quickstart":{"code":"import getBuildNumber from 'build-number';\n\nfunction getAndLogBuildNumber() {\n  // Simulate a CI environment variable if not running in actual CI\n  // For example, on GitHub Actions, GITHUB_RUN_NUMBER would be set.\n  // process.env.GITHUB_RUN_NUMBER = '12345'; // Uncomment for testing outside CI\n\n  const buildNumber = getBuildNumber();\n\n  if (buildNumber) {\n    console.log(`Detected CI Build Number: ${buildNumber}`);\n    // Example usage: Update a version string, tag a release, etc.\n    // const version = `1.0.0-build.${buildNumber}`;\n    // console.log(`Full version string: ${version}`);\n  } else {\n    console.warn('No CI build number detected. This might be expected outside a CI environment.');\n  }\n}\n\ngetAndLogBuildNumber();","lang":"typescript","description":"Demonstrates how to import and use the `getBuildNumber` function, logging the detected build number or a warning if none is found."},"warnings":[{"fix":"Always check for a non-null/non-undefined return value before using the build number, especially in local development or non-CI contexts.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For ESM, always use `import getBuildNumber from 'build-number';`. For CommonJS, use `const getBuildNumber = require('build-number');`.","message":"The `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.","severity":"gotcha","affected_versions":"1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For CommonJS: `const getBuildNumber = require('build-number');`. For ESM: `import getBuildNumber from 'build-number';`.","cause":"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.","error":"TypeError: buildNumber is not a function"},{"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');`.","cause":"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).","error":"SyntaxError: Cannot use import statement outside a module"},{"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.","cause":"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.","error":"My script logs 'No CI build number detected' even though I'm in CI!"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}