# @cucumber/ci-environment

> Detect CI Environment from environment variables

Latest version **15.0.0** (published 2026-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install @cucumber/ci-environment
pnpm add @cucumber/ci-environment
yarn add @cucumber/ci-environment
bun add @cucumber/ci-environment
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 15.0.0 |
| Published | 2026-08-05 |
| First published | 2021-12-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 34.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 14 |
| Author | Cucumber Limited |
| Maintainers | cukebot |
| Keywords | cucumber |

## Links

- npm: https://www.npmjs.com/package/@cucumber/ci-environment
- Repository: https://github.com/cucumber/ci-environment
- Issues: https://github.com/cucumber/ci-environment/issues
- npm.io page: https://npm.io/package/@cucumber/ci-environment

## Recent versions

- 15.0.0 (latest) — 2026-08-05
- 14.0.0 — 2026-06-11
- 13.0.0 — 2026-01-26
- 12.0.0 — 2025-10-27
- 11.0.0 — 2025-10-07
- 10.0.1 — 2024-01-15
- 10.0.0 — 2023-11-16
- 9.2.0 — 2023-04-28
- 9.1.0 — 2022-07-27
- 9.0.4 — 2022-03-06
- 9.0.3 — 2022-03-04
- 9.0.2 — 2022-03-04
- 9.0.1 — 2022-03-04
- 9.0.0 — 2022-01-25
- 8.1.0 — 2022-01-02
- … 4 more at https://npm.io/package/@cucumber/ci-environment/versions

## README

# CiEnvironment

[![test-java](https://github.com/cucumber/ci-environment/actions/workflows/test-java.yaml/badge.svg)](https://github.com/cucumber/ci-environment/actions/workflows/test-java.yaml)
[![test-javascript](https://github.com/cucumber/ci-environment/actions/workflows/test-javascript.yaml/badge.svg)](https://github.com/cucumber/ci-environment/actions/workflows/test-javascript.yaml)
[![test-ruby](https://github.com/cucumber/ci-environment/actions/workflows/test-ruby.yaml/badge.svg)](https://github.com/cucumber/ci-environment/actions/workflows/test-ruby.yaml)
[![test-go](https://github.com/cucumber/ci-environment/actions/workflows/test-go.yaml/badge.svg)](https://github.com/cucumber/ci-environment/actions/workflows/test-go.yaml)

This library detects the CI environment based on environment variables defined
by CI servers.

If a CI server is detected, a `CiEnvironment.json` struct is returned:

```json5
{
  "name": "...",
  "url": "...",
  "buildNumber": "...", // optional
  "git": {              // optional
    "remote": "...",
    "revision": "...",
    "branch": "...",    // optional
    "tag": "..."        // optional
  }
}
```

Note that some fields are optional (they may not be set if the corresponding environment
variables are not defined).

Some CI servers expose usernames and passwords in the environment variable
that is used to detect `git.remote`. For security reasons, this library removes
the username and password from the `git.remote` field in the `CiEnvironment.json` struct.

### TypeScript

```shell
npm install @cucumber/ci-environment
```

```typescript
import detectCiEnvironment from '@cucumber/ci-environment'

const ciEnvironment = detectCiEnvironment(process.env)
console.log(JSON.stringify(ciEnvironment, null, 2))
```

### Java

```xml
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>ci-environment</artifactId>
</dependency>
```

```java
import static io.cucumber.cienvironment.DetectCiEnvironment.detectCiEnvironment;

public class CiEnvironmentExample {
    public static void main(String[] args) {
        CiEnvironment ciEnvironment = detectCiEnvironment(System.getenv()).orElseThrow(() -> new RuntimeException("No CI environment detected"));
        System.out.println("ciEnvironment = " + ciEnvironment);
    }
}
```

### Ruby

```ruby
gem 'cucumber-ci-environment'
```

```ruby
require 'cucumber/ci_environment'

ci_environment = Cucumber::CiEnvironment.detect_ci_environment(ENV)
p ci_environment
```

### Go

```shell
go get github.com/cucumber/ci-environment/go@latest
```

```Go
import (
  "fmt"
	cienvironment "github.com/cucumber/ci-environment/go"
)

func main() {
  ci := cienvironment.DetectCIEnvironment()
  if ci == nil {
    fmt.Println("No CI environment detected")
  }
}
```

### Python

```console
pip install ci-environment
```

```python
>>> import os
>>> from ci_environment import detect_ci_environment
>>> ci_environment = detect_ci_environment(os.environ)
```

## Supported CI servers

* [Azure Pipelines](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables?tabs=yaml&view=azure-devops#build-variables)
* [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html)
* [Buddy](https://buddy.works/docs/pipelines/environment-variables#default-environment-variables)
* [Bitrise](https://devcenter.bitrise.io/builds/available-environment-variables/)
* [CircleCI](https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables)
* [CodeFresh](https://codefresh.io/docs/docs/codefresh-yaml/variables/#system-provided-variables)
* [CodeShip](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables/)
* [GitHub Actions](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables)
* [GitLab](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)
* [GoCD](https://docs.gocd.org/current/faq/dev_use_current_revision_in_build.html)
* [Jenkins](https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#using-environment-variables) and [Jenkins Git plugin](https://plugins.jenkins.io/git/#environment-variables)
* [JetBrains Space](https://www.jetbrains.com/help/space/automation-parameters.html#use-provided-parameters)
* [Semaphore](https://docs.semaphoreci.com/ci-cd-environment/environment-variables/)
* [Travis CI](https://docs.travis-ci.com/user/environment-variables/#Default-Environment-Variables)
* [Wercker](https://devcenter.wercker.com/administration/environment-variables/available-env-vars/)

## Contributing

Please see [CONTRIBUTING.md](./CONTRIBUTING.md) for more information.

---
_Source: https://npm.io/package/@cucumber/ci-environment · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
