What is env-ci?
The env-ci npm package is designed to detect the CI environment in which your code is running. It provides information about the Continuous Integration (CI) service, such as the branch name, commit SHA, and other relevant details. This can be useful for customizing behavior based on the CI environment.
What are env-ci's main functionalities?
Detect CI Environment
This feature allows you to detect if your code is running in a CI environment and provides details about the CI service, branch, and commit. The code sample demonstrates how to use the env-ci package to retrieve and log this information.
const envCi = require('env-ci');
const { isCi, service, branch, commit } = envCi();
console.log(`Running on CI: ${isCi}`);
console.log(`CI Service: ${service}`);
console.log(`Branch: ${branch}`);
console.log(`Commit: ${commit}`);
Custom CI Services
This feature allows you to add custom CI services to the detection logic. The code sample demonstrates how to configure a custom CI service and retrieve information about the branch and commit.
const envCi = require('env-ci');
const { isCi, service, branch, commit } = envCi({
services: [
{
name: 'custom-ci',
detect: () => Boolean(process.env.CUSTOM_CI),
configuration: () => ({
branch: process.env.CUSTOM_CI_BRANCH,
commit: process.env.CUSTOM_CI_COMMIT
})
}
]
});
console.log(`Running on CI: ${isCi}`);
console.log(`CI Service: ${service}`);
console.log(`Branch: ${branch}`);
console.log(`Commit: ${commit}`);
Other packages similar to env-ci
ci-info
The ci-info package provides information about the current Continuous Integration environment. It can detect various CI services and provide details such as the service name and whether the code is running in a CI environment. Compared to env-ci, ci-info is more focused on providing basic CI detection without additional configuration options.
ci-env
The ci-env package is another tool for detecting the CI environment. It provides information about the CI service, branch, and commit. Similar to env-ci, ci-env aims to provide detailed information about the CI environment, but it may not support as many CI services or custom configurations as env-ci.
env-ci
Get environment variables exposed by CI services.
Adapted from codecov-node.
Install
$ npm install --save env-ci
Usage
const envCi = require('env-ci');
const {isCi, service, commit, build, buildUrl, branch, job, jobUrl, pr, isPr, slug, root} = envCi();
Variables
Variable | Description |
---|
isCi | true is running on a CI, false otherwise |
service | CI service name |
commit | Commit sha that triggered the CI build |
build | CI service build number |
buildUrl | Link to the CI service build |
branch | Git branch being built or targeted by a pull request |
job | CI service job number |
jobUrl | Link to the CI service job |
pr | Pull Request number |
isPr | true is the build has been triggered by a Pull Request, false otherwise |
slug | The slug (in form: owner_name/repo_name) of the repository currently being built. |
root | The path to the directory where the repository is being built |
Supported CI
If none of the above CI services is detected, commit
and branch
are determined based on the local Git repository, and isCi
is determined based on the CI
environment variable.