1.0.0 • Published 5 years ago

ci-info-next v1.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

ci-info-next

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 ci-info-next

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

$ yarn add ci-info-next

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('ci-info-next');
    
    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('ci-info-next');
    
    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('ci-info-next');
    
    console.log(isPR()); // Logs: true
  • object vendors: containing the supported CI services.

Supported CI vendors

NameConstantSupports PR detection
AppVeyorAPPVEYORYes
AWS CodeBuildAWS_CODEBUILDNo
Azure PipelinesAZURE_PIPELINESYes
BambooBAMBOONo
Bitbucket PipelinesBITBUCKETYes
BitriseBITRISEYes
BuddyBUDDYYes
BuildkiteBUILDKITEYes
CircleCICIRCLEYes
Cirrus CICIRRUSYes
CodeshipCODESHIPNo
DroneDRONEYes
dsariDSARINo
GitHub ActionsGITHUBYes
GitLab CIGITLABNo
GoCDGOCDNo
HudsonHUDSONNo
JenkinsJENKINSYes
Netlify BuildNETLIFYYes
NevercodeNEVERCODEYes
Sail CISAILYes
SemaphoreSEMAPHOREYes
ShippableSHIPPABLEYes
Strider CDSTRIDERNo
TaskClusterTASKCLUSTERNo
TeamCityTEAMCITYNo
Travis CITRAVISYes

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