env-ci
Get environment variables exposed by CI services.
Adapted from codecov-node.
Install
$ npm install --save env-ci
Usage
import envCi from "env-ci";
const {
name,
service,
isCi,
branch,
commit,
tag,
build,
buildUrl,
job,
jobUrl,
isPr,
pr,
prBranch,
slug,
root,
} = envCi();
if (isCI) {
console.log(`Building repo ${slug} on ${name} service`);
if (isPr) {
console.log(
`Building Pull Request #${pr} originating from branch ${prBranch} and targeting branch ${branch}`,
);
} else {
console.log(`Building branch ${branch}`);
}
if (service === "travis") {
// Do something specific to Travis CI
}
}
Supported variables
Variable | Description |
---|---|
name | CI service Commercial name (e.g. Travis CI , CircleCI , GitLab CI/CD ) |
service | Standardized CI service name (e.g. travis , circleci , gitlab ) |
isCi | true is running on a CI, false otherwise |
branch | Git branch being built or targeted by a Pull Request |
commit | Commit sha that triggered the CI build |
tag | Git tag that triggered the CI build |
build | CI service build number |
buildUrl | Link to the CI service build |
job | CI service job number |
jobUrl | Link to the CI service job |
isPr | true if the build has been triggered by a Pull Request, false otherwise |
pr | Pull Request number (only for builds triggered by a Pull Request) |
prBranch | Git branch branch from which the Pull Request originated (only for builds triggered by a Pull Request) |
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 |
Note: Some variables can be detected only on certain CI services. See Supported CI.
Note: The pr
and prBranch
properties are only available for builds triggered when a Pull Request is
opened/updated and not on builds triggered by a push on a branch even if that branch happens to be the branch from which
the Pull Request originated.
Supported CI
CI Service (name ) | service | isCi | branch | commit | tag | build | buildUrl | job | jobUrl | isPr | pr | prBranch | slug | root |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AppVeyor | appveyor | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Azure Pipelines | azure-devops | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: |
Bamboo | bamboo | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: |
Bitbucket | bitbucket | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: |
Bitrise | bitrise | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
Buddy | buddy | :white_check_mark: | :warning: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :x: |
Buildkite | buildkite | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
CircleCI | circleci | :white_check_mark: | :warning: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: |
Cirrus CI | cirrus | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Cloudflare Pages | cloudflarePages | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: |
AWS CodeBuild | codebuild | :white_check_mark: | :warning: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: |
Codefresh | codefresh | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Codeship | codeship | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :x: |
Drone | drone | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
GitHub Actions | github | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
GitLab CI/CD | gitlab | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Jenkins | jenkins | :white_check_mark: | :warning: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :warning: | :warning: | :warning: | :white_check_mark: | :white_check_mark: |
Netlify | netlify | :white_check_mark: | :warning: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Puppet | puppet | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: |
Sail CI | sail | :white_check_mark: | :warning: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: |
Screwdriver.cd | screwdriver | :white_check_mark: | :warning: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Scrutinizer | scrutinizer | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :x: |
Semaphore | semaphore | :white_check_mark: | :warning: | :white_check_mark: | :warning: | :white_check_mark: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Shippable | shippable | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
TeamCity | teamcity | :white_check_mark: | :white_check_mark: | :white_check_mark: | :x: | :white_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :white_check_mark: | :white_check_mark: |
Travis CI | travis | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Vela | vela | :white_check_mark: | :white_check_mark: | :white_check_mark: | :white_check_mark: |