{"id":13464972,"url":"https://github.com/semantic-release/env-ci","last_synced_at":"2025-05-14T12:08:32.757Z","repository":{"id":38091778,"uuid":"114841957","full_name":"semantic-release/env-ci","owner":"semantic-release","description":"Get environment variables exposed by CI services","archived":false,"fork":false,"pushed_at":"2025-04-07T05:46:14.000Z","size":1289,"stargazers_count":231,"open_issues_count":12,"forks_count":48,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-11T04:57:35.658Z","etag":null,"topics":["appveyor","bamboo","bitbucket","bitrise","buddy","buildkite","ci","circleci","cirrus-ci","codeship","continuous-integration","drone","environment","gitlab","jenkins","semaphore","shippable","travis","vsts","wercker"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/semantic-release.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-20T04:15:19.000Z","updated_at":"2025-04-07T17:54:00.000Z","dependencies_parsed_at":"2024-11-09T12:31:30.348Z","dependency_job_id":"cba4a16f-1b54-4b80-83be-4f2f29ed366a","html_url":"https://github.com/semantic-release/env-ci","commit_stats":{"total_commits":376,"total_committers":29,"mean_commits":12.96551724137931,"dds":0.4920212765957447,"last_synced_commit":"7e29f58a4ae36d57ab69596e1c7cc013679d2e2f"},"previous_names":["pvdlg/env-ci"],"tags_count":76,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semantic-release%2Fenv-ci","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semantic-release%2Fenv-ci/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semantic-release%2Fenv-ci/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semantic-release%2Fenv-ci/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/semantic-release","download_url":"https://codeload.github.com/semantic-release/env-ci/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345273,"owners_count":21088244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appveyor","bamboo","bitbucket","bitrise","buddy","buildkite","ci","circleci","cirrus-ci","codeship","continuous-integration","drone","environment","gitlab","jenkins","semaphore","shippable","travis","vsts","wercker"],"created_at":"2024-07-31T14:00:53.727Z","updated_at":"2025-04-11T04:57:45.237Z","avatar_url":"https://github.com/semantic-release.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# env-ci\n\nGet environment variables exposed by CI services.\n\n[![Build Status](https://github.com/semantic-release/env-ci/workflows/Test/badge.svg)](https://github.com/semantic-release/env-ci/actions?query=workflow%3ATest+branch%3Amaster)\n[![npm latest version](https://img.shields.io/npm/v/env-ci/latest.svg)](https://www.npmjs.com/package/env-ci)\n\nAdapted from [codecov-node](https://github.com/codecov/codecov-node/blob/master/lib/detect.js).\n\n## Install\n\n```bash\n$ npm install --save env-ci\n```\n\n## Usage\n\n```js\nimport envCi from \"env-ci\";\n\nconst {\n  name,\n  service,\n  isCi,\n  branch,\n  commit,\n  tag,\n  build,\n  buildUrl,\n  job,\n  jobUrl,\n  isPr,\n  pr,\n  prBranch,\n  slug,\n  root,\n} = envCi();\n\nif (isCI) {\n  console.log(`Building repo ${slug} on ${name} service`);\n\n  if (isPr) {\n    console.log(\n      `Building Pull Request #${pr} originating from branch ${prBranch} and targeting branch ${branch}`,\n    );\n  } else {\n    console.log(`Building branch ${branch}`);\n  }\n\n  if (service === \"travis\") {\n    // Do something specific to Travis CI\n  }\n}\n```\n\n## Supported variables\n\n| Variable   | Description                                                                                            |\n| ---------- | ------------------------------------------------------------------------------------------------------ |\n| `name`     | CI service Commercial name (e.g. `Travis CI`, `CircleCI`, `GitLab CI/CD`)                              |\n| `service`  | Standardized CI service name (e.g. `travis`, `circleci`, `gitlab`)                                     |\n| `isCi`     | `true` is running on a CI, `false` otherwise                                                           |\n| `branch`   | Git branch being built or targeted by a Pull Request                                                   |\n| `commit`   | Commit sha that triggered the CI build                                                                 |\n| `tag`      | Git tag that triggered the CI build                                                                    |\n| `build`    | CI service build number                                                                                |\n| `buildUrl` | Link to the CI service build                                                                           |\n| `job`      | CI service job number                                                                                  |\n| `jobUrl`   | Link to the CI service job                                                                             |\n| `isPr`     | `true` if the build has been triggered by a Pull Request, `false` otherwise                            |\n| `pr`       | Pull Request number (only for builds triggered by a Pull Request)                                      |\n| `prBranch` | Git branch branch from which the Pull Request originated (only for builds triggered by a Pull Request) |\n| `slug`     | The slug (in form: owner_name/repo_name) of the repository currently being built                       |\n| `root`     | The path to the directory where the repository is being built                                          |\n\n**Note**: Some variables can be detected only on certain CI services. See [Supported CI](#supported-ci).\n\n**Note**: The `pr` and `prBranch` properties are only available for builds triggered when a Pull Request is\nopened/updated and not on builds triggered by a push on a branch even if that branch happens to be the branch from which\nthe Pull Request originated.\n\n## Supported CI\n\n| CI Service (`name`)                                                                                                                    |     `service`     |       `isCi`       |          `branch`           |      `commit`      |          `tag`          |      `build`       |     `buildUrl`     |       `job`        |      `jobUrl`      |        `isPr`         |         `pr`          |      `prBranch`       |       `slug`       |       `root`       |\n| -------------------------------------------------------------------------------------------------------------------------------------- | :---------------: | :----------------: | :-------------------------: | :----------------: | :---------------------: | :----------------: | :----------------: | :----------------: | :----------------: | :-------------------: | :-------------------: | :-------------------: | :----------------: | :----------------: |\n| [AppVeyor](https://www.appveyor.com/docs/environment-variables)                                                                        |    `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: |\n| [Azure Pipelines](https://docs.microsoft.com/en-us/azure/devops/pipelines/build/variables)                                             |  `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: |\n| [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html)                                                      |     `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: |\n| [Bitbucket](https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html)                                           |    `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: |\n| [Bitrise](https://devcenter.bitrise.io/builds/available-environment-variables/#exposed-by-bitriseio)                                   |     `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:         |\n| [Buddy](https://buddy.works/knowledge/deployments/how-use-environment-variables#default-environment-variables)                         |      `buddy`      | :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:   |          :x:          | :white_check_mark: |        :x:         |\n| [Buildkite](https://buildkite.com/docs/builds/environment-variables)                                                                   |    `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: |\n| [CircleCI](https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables)                                                     |    `circleci`     | :white_check_mark: |   [:warning:](#circleci)    | :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:         |\n| [Cirrus CI](https://cirrus-ci.org/guide/writing-tasks/#environment-variables)                                                          |     `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: |\n| [Cloudflare Pages](https://developers.cloudflare.com/pages/platform/build-configuration#environment-variables)                         | `cloudflarePages` | :white_check_mark: |     :white_check_mark:      | :white_check_mark: |           :x:           |        :x:         |        :x:         |        :x:         |        :x:         |          :x:          |          :x:          |          :x:          |        :x:         | :white_check_mark: |\n| [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html)                                    |    `codebuild`    | :white_check_mark: | [:warning:](#aws-codebuild) | :white_check_mark: |           :x:           | :white_check_mark: | :white_check_mark: |        :x:         |        :x:         |          :x:          |          :x:          |          :x:          |        :x:         | :white_check_mark: |\n| [Codefresh](https://codefresh.io/docs/docs/codefresh-yaml/variables#system-provided-variables)                                         |    `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: |\n| [Codeship](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables/#default-environment-variables) |    `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:         |\n| [Drone](https://readme.drone.io/reference/environ/)                                                                                    |      `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: |\n| [GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables)          |     `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: |\n| [GitLab CI/CD](https://docs.gitlab.com/ce/ci/variables/README.html)                                                                    |     `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: |\n| [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project)                                                         |     `jenkins`     | :white_check_mark: |    [:warning:](#jenkins)    | :white_check_mark: |           :x:           | :white_check_mark: | :white_check_mark: |        :x:         |        :x:         | [:warning:](#jenkins) | [:warning:](#jenkins) | [:warning:](#jenkins) | :white_check_mark: | :white_check_mark: |\n| [Netlify](https://docs.netlify.com/configure-builds/environment-variables/#netlify-configuration-variables)                            |     `netlify`     | :white_check_mark: |    [:warning:](#netlify)    | :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: |\n| [Puppet](https://puppet.com/docs/pipelines-for-apps/enterprise/environment-variable.html)                                              |     `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: |\n| [Sail CI](https://sail.ci/docs/environment-variables)                                                                                  |      `sail`       | :white_check_mark: |     [:warning:](#sail)      | :white_check_mark: |           :x:           |        :x:         |        :x:         |        :x:         |        :x:         |  :white_check_mark:   |  :white_check_mark:   |          :x:          | :white_check_mark: | :white_check_mark: |\n| [Screwdriver.cd](https://docs.screwdriver.cd/user-guide/environment-variables)                                                         |   `screwdriver`   | :white_check_mark: |  [:warning:](#screwdriver)  | :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: |\n| [Scrutinizer](https://scrutinizer-ci.com/docs/build/environment-variables)                                                             |   `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:         |\n| [Semaphore](https://docs.semaphoreci.com/article/12-environment-variables)                                                             |    `semaphore`    | :white_check_mark: |   [:warning:](#semaphore)   | :white_check_mark: | [:warning:](#semaphore) | :white_check_mark: |        :x:         |        :x:         |        :x:         |  :white_check_mark:   |  :white_check_mark:   |  :white_check_mark:   | :white_check_mark: | :white_check_mark: |\n| [Shippable](http://docs.shippable.com/ci/env-vars/#stdEnv)                                                                             |    `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: |\n| [TeamCity](https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters)                                                 |    `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: |\n| [Travis CI](https://docs.travis-ci.com/user/environment-variables#default-environment-variables)                                       |     `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: |\n| [Vela](https://go-vela.github.io/docs/reference/environment/variables/)                                                                |      `vela`       | :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: |\n| [Vercel](https://vercel.com/docs/environment-variables)                                                                                |     `vercel`      | :white_check_mark: |     :white_check_mark:      | :white_check_mark: |           :x:           |        :x:         |        :x:         |        :x:         |        :x:         |          :x:          |          :x:          |          :x:          | :white_check_mark: |        :x:         |\n| [Wercker](http://devcenter.wercker.com/docs/environment-variables/available-env-vars#hs_cos_wrapper_name)                              |     `wercker`     | :white_check_mark: |     :white_check_mark:      | :white_check_mark: |           :x:           | :white_check_mark: | :white_check_mark: |        :x:         |        :x:         |          :x:          |          :x:          |          :x:          | :white_check_mark: | :white_check_mark: |\n| [JetBrains Space](https://www.jetbrains.com/space/)                                                                                    | `jetbrainsSpace`  | :white_check_mark: |     :white_check_mark:      | :white_check_mark: |           :x:           | :white_check_mark: |        :x:         |        :x:         |        :x:         |          :x:          |          :x:          |          :x:          | :white_check_mark: |        :x:         |\n| [Woodpecker CI](https://woodpecker-ci.org/docs/usage/environment#built-in-environment-variables)                                       |   `woodpecker`    | :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: |\n\n:warning: See [Caveats](#caveats)\n\n**Note**: Unsupported properties will always be `undefined`. For example if a Ci services doesn't support triggering\nbuilds when a Pull Request is opened/updated, `isPr` will be `undefined`.\n\n**Note**: If none of the above CI services is detected, `commit` and `branch` are determined based on the local Git\nrepository, and `isCi` is determined based on the `CI` environment variable.\n\n## API\n\n### envCi(options) =\u003e Result\n\n#### options\n\nType: `Object`\n\n#### env\n\nType: `Object`\u003cbr\u003e\nDefault: `process.env`\n\nThe object to read environment variables from.\n\n#### cwd\n\nType: `String`\u003cbr\u003e\nDefault: `process.cwd()`\n\nThe current working directory in which to execute `git` commands used to determine the `commit`\nand `branch` [Result](#result) properties in case no [supported CI](#supported-ci) is detected.\n\n### Result\n\nType: `Object`\n\n[Environment variables values](#supported-variables) exposed by the CI service.\n\n## Caveats\n\n### AWS CodeBuild\n\nAWS CodeBuild doesn't provide an environment variable to determine the current Git branch being built. In addition, it\nclones the repository in a [detached head state](https://git-scm.com/docs/git-checkout#_detached_head) so the branch\ncannot be determined with `git rev-parse --abbrev-ref HEAD`.\nTo work around this limitation, `env-ci` look for the remote branches having the same `HEAD` as the local\ndetached `HEAD` to determine the branch from which the detached `HEAD` was created.\nIn the rare case where there is multiple remote branches with the same `HEAD` as the local detached `HEAD`, `env-ci`\nwill arbitrarily pick the first one. This can lead to an inaccurate `branch` value in such circumstances.\n\n### CircleCI\n\nFor builds triggered when a Pull Request is opened/updated, CircleCI doesn't provide an environment variable indicating\nthe target branch.\nTherefore, in the case of Pull Request builds, `env-ci` will not be able to determine the `branch` property.\nHowever `prBranch` will be set.\n\nSee [feature request](https://discuss.circleci.com/t/create-a-circle-target-branch-envar/10022).\n\n### Cloudflare Pages\n\nFor builds triggered when a Pull Request is opened/updated, Cloudflare Pages will re-use the branch variable for the\noriginating branch and not provide a target. Therefore `env-ci` will not be able to determine the `prBranch` property\nhowever `branch` will always be set.\n\n### Jenkins\n\nTriggering build when a Pull Request is opened/updated is supported only via\nthe [ghprb-plugin](https://github.com/jenkinsci/ghprb-plugin)\nand [gitlab-plugin](https://github.com/jenkinsci/gitlab-plugin). Therefore `env-ci` will set `isPr`, `pr` and `prBranch`\nand define `branch` with the Pull Request target branch only if one those plugin is used.\n\n### Netlify\n\nFor builds triggered when a Pull Request is opened/updated, Netlify doesn't provide an environment variable indicating\nthe target branch.\nTherefore, in the case of Pull Request builds, `env-ci` will not be able to determine the `branch` property.\nHowever `prBranch` will be set.\n\nSee [feature request](https://answers.netlify.com/t/access-pr-target-branch-when-deploying-preview-build/32402)\n\n### Sail\n\nFor builds triggered when a Pull Request is opened/updated, Sail doesn't provide an environment variable indicating the\ntarget branch, and the one for the current branch is set to `pull/\u003cPR number\u003e` independently of the the branch name from\nwhich the Pull Request originated.\nTherefore, in the case of Pull Request builds, `env-ci` will not be able to determine the `branch` and `prBranch`\nproperties.\n\n### Semaphore\n\nFor builds triggered when a Pull Request is opened/updated, Semaphore 1.0 doesn't provide an environment variable\nindicating the target branch.\nTherefore, in the case of Pull Request builds, `env-ci` will not be able to determine the `branch` property.\nHowever `prBranch` will be set.\nOn Semaphore 2.0 the `branch` and `prBranch` properties will work as expected.\n\nThe property `tag` is only available on Semaphore 2.0.\n\n### Screwdriver\n\nFor builds triggered when a Pull Request is opened/updated, Screwdriver sets the `env.GIT_BRANCH` as `head:pr` branch\ntype (Example:`origin/refs/pull/1/head:pr`) while at commit level (non PR) it does set it with the actual branch (Example: `origin/main`).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemantic-release%2Fenv-ci","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsemantic-release%2Fenv-ci","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemantic-release%2Fenv-ci/lists"}