Detect CI Environment
The `is-ci` package provides a minimalist, direct method for determining whether the current process is executing within a Continuous Integration (CI) environment. It exposes a simple boolean value (`true` if running in CI, `false` otherwise), abstracting away the complexities of checking various environment variables across different CI providers. The current stable version is `4.1.0`. The library typically sees updates in conjunction with its underlying dependency, `ci-info`, which is responsible for the core detection logic, leading to an irregular but feature-driven release cadence. Its primary differentiator is its singular focus on providing a simple boolean answer, making it ideal for conditional logic in build scripts, test runners, or deployment pipelines where CI context is crucial. It supports a wide array of CI services by leveraging `ci-info`'s comprehensive detection capabilities.
Common errors
-
TypeError: isCI is not a function
cause Attempting to invoke the `isCI` boolean as if it were a function.fixUse `isCI` directly as a boolean. Correct: `if (isCI) { ... }`. Incorrect: `if (isCI()) { ... }`. -
ReferenceError: require is not defined in ES module scope
cause Using `require('is-ci')` in an ES Module context (e.g., in a `.mjs` file or a project with `"type": "module"` in `package.json`) without proper transpilation.fixFor ES Modules, use `import isCI from 'is-ci';`. If you must use CommonJS modules, ensure your file is `.js` and your `package.json` does not specify `"type": "module"`, or use a bundler/transpiler configured for CommonJS.
Warnings
- breaking Version 4.0.0 of `is-ci` updated its underlying `ci-info` dependency to v4.0.0, which introduced breaking changes by removing support for certain CI services. Specifically, detection for 'Shippable CI' and 'Solano CI' (formerly 'TDDium') was removed.
- gotcha The `is-ci` package exports a simple boolean value, not a function or an object with properties. Attempting to call it as a function (`isCI()`) or access properties on it (`isCI.value`) will result in errors.
Install
-
npm install is-ci -
yarn add is-ci -
pnpm add is-ci
Imports
- isCI
import { isCI } from 'is-ci';import isCI from 'is-ci';
- isCI
const isCI = require('is-ci'); - isCI (TypeScript)
import isCI from 'is-ci';
Quickstart
import isCI from 'is-ci';
console.log(`Checking CI status (ESM):`);
if (isCI) {
console.log(' This code is running on a CI server.');
} else {
console.log(' This code is NOT running on a CI server.');
}
// For CommonJS environments:
/*
const isCI_cjs = require('is-ci');
console.log(`\nChecking CI status (CJS):`);
if (isCI_cjs) {
console.log(' This CJS code is running on a CI server.');
} else {
console.log(' This CJS code is NOT running on a CI server.');
}
*/
// Example of conditional logic based on CI detection
if (isCI && process.env.NODE_ENV === 'production') {
console.log('\nRunning production build steps on CI...');
} else if (!isCI && process.env.NODE_ENV === 'development') {
console.log('\nRunning local development tasks...');
}