@niktekusho/ci-info
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-0 • Public • Published

ci-info

Get details of the current CI environment. This library is heavily inspired by https://github.com/watson/ci-info.

Installation

Note: this library needs Node.js and a console you can type in commands (PowerShell on Windows, Terminal on macOS and your favorite terminal emulator on every other OS). The minimum required version of Node.js is: 8 - codename "Carbon".

In your console, run the following command:

$ npm install @niktekusho/ci-info

You can also use yarn (like we do in this project):

$ yarn add @niktekusho/ci-info

Usage

The library exports the following API:

  • function detectVendor: get an array of possible CI vendors based on the defined environment variables;

    // process.env: TRAVIS='',TRAVIS_PULL_REQUEST=''
    const {detectVendor} = require('@niktekusho/ci-info');
    
    console.log(detectVendor()); // Logs: ['TRAVIS']
  • function isCI: detect if the current environment is running on a Continuous Integration service;

    // On your PC
    const {isCI} = require('@niktekusho/ci-info');
    
    console.log(isCI()); // Logs: false
    
    // On a CI service...
    console.log(isCI()); // Logs: true
  • function isPR: detect if the current environment is running on Pull Request build within a Continuous Integration service;

    // process.env: TRAVIS='',TRAVIS_PULL_REQUEST=''
    const {isPR} = require('@niktekusho/ci-info');
    
    console.log(isPR()); // Logs: true
  • object vendors: containing the supported CI services.

Supported CI vendors

Name Constant Supports PR detection
AppVeyor APPVEYOR Yes
AWS CodeBuild AWS_CODEBUILD No
Azure Pipelines AZURE_PIPELINES Yes
Bamboo BAMBOO No
Bitbucket Pipelines BITBUCKET Yes
Bitrise BITRISE Yes
Buddy BUDDY Yes
Buildkite BUILDKITE Yes
CircleCI CIRCLE Yes
Cirrus CI CIRRUS Yes
Codeship CODESHIP No
Drone DRONE Yes
dsari DSARI No
GitLab CI GITLAB No
GoCD GOCD No
Hudson HUDSON No
Jenkins JENKINS Yes
Netlify Build NETLIFY Yes
Nevercode NEVERCODE Yes
Sail CI SAIL Yes
Semaphore SEMAPHORE Yes
Shippable SHIPPABLE Yes
Strider CD STRIDER No
TaskCluster TASKCLUSTER No
TeamCity TEAMCITY No
Travis CI TRAVIS Yes

API

CIVendor

name

Pretty-printable name of the CI Vendor, for example 'Travis CI'.

constant

This property is an internal "id" of the CI Vendor. This library enforces an uppercased format, for example 'TRAVIS'.

detectEnvFunction(envs)

This function checks if the specified environment variables match this vendor's required environment variables. Returns true if the current environment variables suggest that this vendor could be the one in use. Throws a TypeError if the specified envs argument is not of type 'object'.

envs

Type: object

Environment variables object that allows you to override the default process environment.

detectPRFunction(envs)

This function checks if the specified environment variables match this vendor's required environment variables for Pull Requests. Returns true if the current environment variables suggest that this vendor could be the one in use. This function returns null if the vendor does not provide a reliable way to check for a PR environment.

Throws a TypeError if the specified envs argument is not of type 'object'.

envs

Type: object

Environment variables object that allows you to override the default process environment.

detectVendor(envs?)

Returns: CIVendor[]

Tries to detect which vendors match the specified environment and returns an array of the vendors matching the specified environment.

envs

Type: object
Default: process.env

Environment variables object that allows you to override the default process environment.

isCI(envs?)

This function returns whether the specified environment variables suggest a CI environment.

envs

Type: object
Default: process.env

Environment variables object that allows you to override the default process environment.

isPR(envs?)

Returns whether the specified environment variables suggest a PR build in the CI system.

envs

Type: object
Default: process.env

Environment variables object that allows you to override the default process environment.

vendors

This object contains all the supported CI vendors, both individually (using the CIVendor.CONSTANT property) and collectively (all property).

Related

Readme

Keywords

none

Package Sidebar

Install

npm i @niktekusho/ci-info

Weekly Downloads

0

Version

0.0.1-0

License

MIT

Unpacked Size

27.5 kB

Total Files

8

Last publish

Collaborators

  • niktekusho