Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@cucumber/ci-environment

cucumber4.4mMIT10.0.1TypeScript support: included

Detect CI Environment from environment variables

cucumber

readme

CiEnvironment

test-java test-javascript test-ruby test-go

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

If a CI server is detected, a CiEnvironment struct is returned:

{
  "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 struct.

TypeScript

npm install @cucumber/ci-environment
import detectCiEnvironment from '@cucumber/ci-environment'

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

Java

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>ci-environment</artifactId>
</dependency>
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

gem 'cucumber-ci-environment'
require 'cucumber/ci_environment'

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

Go

go get github.com/cucumber/ci-environment/go@latest
import (
  "fmt"
    cienvironment "github.com/cucumber/ci-environment/go"
)

func main() {
  ci := cienvironment.DetectCIEnvironment()
  if ci == nil {
    fmt.Println("No CI environment detected")
  }
}
import os
from ci_environment import detect_ci_environment

ci_environment = detect_ci_environment(os.environ)

Supported CI servers

Contributing

Please see CONTRIBUTING.md for more information.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased

10.0.1 - 2024-01-15

Added

  • [Python] added release workflow to release to Pypi (#245)

10.0.0 - 2023-11-16

Added

  • [Python] added ci-environment implementation in Python
  • [Ruby] Initial rubocop configuration added (#228)

Changed

  • [Ruby] Minimum ruby version is now 2.6 (#228)

9.2.0 - 2023-04-28

Added

9.1.0 - 2022-07-27

Added

  • [Go] added ci-environment implementation in Go

Fixed

  • [Java] Escape regex replacement patterns in environment variables (#156, #157)

9.0.4 - 2022-03-06

Fixed

  • [Java] Make DetectCiEnvironment.detectCiEnvironment public

9.0.3 - 2022-03-04

Fixed

  • Handle GitHub Action opened as well as synchronize event (and any other pull_request event with .pull_request.head.sha in the event payload) (#86, #87)

9.0.2 - 2022-03-04

Fixed

  • Correctly determine GitHub branch from GITHUB_HEAD_REF instead of GITHUB_REF (#85)
  • Better error message if revision cannot be determined from GitHub pull request (#85)

9.0.1 - 2022-03-04

Fixed

  • Provide correct SHA for GitHub Actions (#67, #69)

9.0.0 - 2022-01-25

Added

  • [JavaScript] export Env, Git, CiEnvironment and CiEnvironments types

Changed

  • [JavaScript] make buildNumber optional (#51)
  • [Java] use Optional<T> for optional values (#50)

8.1.0 - 2022-01-02

Added

  • [JavaScript] - package as hybrid esm/commonjs module (#47)

8.0.1 - 2021-12-29

Fixed

  • [Ruby] detect_ci_environment was not returning nil if no CI had been detected

8.0.0 - 2021-12-15

Changed

  • Make git optional, make git.revision and git.remote mandatory (#37)

7.0.1 - 2021-12-08

Fixed

  • Fix Ruby release

7.0.0 - 2021-12-08

Changed

  • This library has been renamed to ci-environment and no longer depends on Cucumber messages. (PR#34)

6.0.4 - 2021-11-16

Fixed

6.0.3 - 2021-11-15

Fixed

  • [JavaScript] Removed tag property from git object if it is undefined (PR#4)

6.0.2 - 2021-10-18

Fixed

  • [Ruby] Generate cucumber messages rather than plain ruby hashes (PR#1772)

6.0.1 - 2021-07-19

Changed

  • Upgrade cucumber-messages to v17.0.1

6.0.0 - 2021-07-08

Added

Changed

  • [Java] Removed implicit utility class constructors and made classes final

Fixed

  • Improve detection of Bamboo environment variables
  • Improve detection of Azure environment variables
  • Fix Git#remote for CodeFresh

Removed

  • Removed support for TeamCity since it doesn't seem to expose enough environment variables.

5.0.0 - 2021-05-17

Added

Changed

  • Upgrade messages to 16.0.0

Fixed

  • Fixed detection of Semaphore build url.
  • Fixed detection of GoCD build url.

4.0.0 - 2021-03-29

Changed

  • Upgrade messages to 15.0.0

3.0.0 - 2021-02-09

Changed

  • Upgrade messages to 14.0.1

2.0.4 - 2020-10-29

Fixed

2.0.2 - 2020-09-03

2.0.1 - 2020-08-18

Fixed

  • Ruby: Add the ci property to meta message

2.0.0 - 2020-08-07

Changed

  • Update messages to 13.0.1

Fixed

  • Java: Use java.vm.name instead of java.vendor (which is N/A on OpenJDK)
  • Java: Use java.vm.version instead of java.version
  • Support GitHub Enterprise by using GITHUB_SERVER_URL to construct URLs

1.2.0 - 2020-07-31

Changed

  • Updated messages to v12.4.0

1.1.0 - 2020-07-30

Changed

  • Updated messages to v12.3.2

1.0.0 - 2020-06-29

Added

  • First release