Detect if the current environment is a CI server
npx @tessl/cli install tessl/npm-is-ci@4.1.00
# is-ci
1
2
Returns `true` if the current environment is a Continuous Integration server. This utility provides both programmatic and command-line interfaces for detecting CI environments across all major CI platforms.
3
4
## Package Information
5
6
- **Package Name**: is-ci
7
- **Package Type**: npm
8
- **Language**: JavaScript (with TypeScript definitions)
9
- **Installation**: `npm install is-ci`
10
11
## Core Imports
12
13
```javascript
14
const isCI = require('is-ci');
15
```
16
17
For TypeScript:
18
19
```typescript
20
import isCI = require('is-ci');
21
```
22
23
## Basic Usage
24
25
```javascript
26
const isCI = require('is-ci');
27
28
if (isCI) {
29
console.log('The code is running on a CI server');
30
} else {
31
console.log('The code is not running on a CI server');
32
}
33
```
34
35
Command-line usage:
36
37
```bash
38
# Install globally or use in package.json scripts
39
is-ci && echo "This is a CI server"
40
41
# Using npx
42
npx is-ci && echo "This is a CI server"
43
44
# Using local installation
45
./node_modules/.bin/is-ci && echo "This is a CI server"
46
```
47
48
## Capabilities
49
50
### CI Detection (Programmatic)
51
52
Detects if the current environment is a Continuous Integration server by checking environment variables and other indicators.
53
54
```javascript { .api }
55
/**
56
* Boolean value indicating whether the current environment is a CI server
57
* @type {boolean}
58
*/
59
const isCI = require('is-ci');
60
```
61
62
**Return Value**: `boolean` - `true` if running in a CI environment, `false` otherwise
63
64
**Dependencies**: This value is derived from the `ci-info` package's `isCI` property, which checks for various CI environment indicators.
65
66
**Usage Example:**
67
68
```javascript
69
const isCI = require('is-ci');
70
71
// Conditional logic based on CI environment
72
if (isCI) {
73
console.log('Running in CI - using production settings');
74
process.env.NODE_ENV = 'production';
75
} else {
76
console.log('Running locally - using development settings');
77
process.env.NODE_ENV = 'development';
78
}
79
```
80
81
### CI Detection (Command Line)
82
83
Command-line interface that exits with status code 0 if in CI environment, 1 otherwise.
84
85
```bash { .api }
86
# Command line usage
87
is-ci
88
89
# Exit codes:
90
# 0 - Running in CI environment
91
# 1 - Not running in CI environment
92
```
93
94
**Installation Options:**
95
- Global: `npm install -g is-ci`
96
- Local dependency: `npm install is-ci` (accessible via `./node_modules/.bin/is-ci`)
97
- Package.json scripts: Use `is-ci` directly in scripts section
98
99
**Usage Examples:**
100
101
```bash
102
# Basic conditional execution
103
is-ci && echo "This is a CI server" || echo "This is not a CI server"
104
105
# In package.json scripts
106
{
107
"scripts": {
108
"ci-only": "is-ci && npm run build:production",
109
"local-only": "is-ci || npm run dev"
110
}
111
}
112
113
# In shell scripts
114
#!/bin/bash
115
if is-ci; then
116
echo "Running CI deployment"
117
npm run deploy
118
else
119
echo "Running local build"
120
npm run build:dev
121
fi
122
```
123
124
## Types
125
126
```typescript { .api }
127
/**
128
* TypeScript definition for the is-ci module
129
* Re-exports the isCI boolean from ci-info package
130
*/
131
declare const isCI: boolean;
132
export = isCI;
133
```
134
135
## Supported CI Platforms
136
137
This package supports all CI platforms supported by the underlying `ci-info` dependency, including but not limited to:
138
139
- GitHub Actions
140
- Travis CI
141
- CircleCI
142
- Jenkins
143
- GitLab CI
144
- Azure DevOps
145
- AWS CodeBuild
146
- Bitbucket Pipelines
147
- And many more
148
149
For the complete list, refer to the [ci-info documentation](https://github.com/watson/ci-info#supported-ci-tools).
150
151
## Error Handling
152
153
This package does not throw exceptions. The programmatic interface always returns a boolean value, and the CLI interface always exits with either status code 0 or 1.