There's a lot of open issues
Detect CI Environment from environment variables
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 13.1
~> 3.12
~> 1.44.0
~> 0.6.0
~> 2.15.0
 Project 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.