Skip to content

Commit

Permalink
feat: add name property (CI commercial name)
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Apr 6, 2018
1 parent 7d2abc4 commit 4d3d673
Show file tree
Hide file tree
Showing 31 changed files with 62 additions and 19 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@ $ npm install --save env-ci
```js
const envCi = require('env-ci');

const {isCi, service, commit, build, buildUrl, branch, job, jobUrl, pr, isPr, slug, root} = envCi();
const {isCi, name, 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 |
| `name` | CI service Commercial name (e.g. `Travis CI`, `CircleCI`, `GitLab CI/CD`) |
| `service` | Standardized CI service name (e.g. `travis`, `circleci`, `gitlab`) |
| `commit` | Commit sha that triggered the CI build |
| `build` | CI service build number |
| `buildUrl` | Link to the CI service build |
Expand All @@ -41,22 +42,22 @@ const {isCi, service, commit, build, buildUrl, branch, job, jobUrl, pr, isPr, sl

## Supported CI

| CI Service | `service` | `isCi` | `commit` | `build` | `buildUrl` | `branch` | `job` | `jobUrl` | `pr` | `isPr` | `slug` | `root` |
|-----------------------------------------------------------------------------------------------------------|:-----------: |:------:|:--------:|:-------:|:----------:|:--------:|:-----:|:--------:|:----:|:------:|:------:|:------:|
| [AppVeyor]( https://www.appveyor.com/docs/environment-variables) | `appveyor` ||||||||||||
| [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html) | `bamboo` ||||||||||||
| [Bitbucket](https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html) | `bitbucket` ||||||||||||
| [Bitrise](http://devcenter.bitrise.io/faq/available-environment-variables/#exposed-by-bitriseio) | `bitrise` ||||||||||||
| [Buildkite](https://buildkite.com/docs/builds/environment-variables) | `buildkite` ||||||||||||
| [Circleci](https://circleci.com/docs/1.0/environment-variables) | `circleci` ||||||||||||
| [Codeship](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables) | `codeship` ||||||||||||
| [Drone](http://readme.drone.io/0.5/usage/environment-reference) | `drone` ||||||||||||
| [Gitlab CI](https://docs.gitlab.com/ce/ci/variables/README.html) | `gitlab` ||||||||||||
| [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project) | `jenkins` ||||||||||||
| [Semaphore](https://semaphoreci.com/docs/available-environment-variables.html) | `semaphore` ||||||||||||
| [Shippable](http://docs.shippable.com/ci/env-vars/#stdEnv) | `shippable` ||||||||||||
| [TeamCity](https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters) | `teamcity` ||||||||||||
| [Travis](https://docs.travis-ci.com/user/environment-variables) | `travis` ||||||||||||
| [Wercker](http://devcenter.wercker.com/docs/environment-variables/available-env-vars#hs_cos_wrapper_name) | `wercker` ||||||||||||
| CI Service (`name`) | `service` | `isCi` | `commit` | `build` | `buildUrl` | `branch` | `job` | `jobUrl` | `pr` | `isPr` | `slug` | `root` |
|-----------------------------------------------------------------------------------------------------------|:-----------:|:------:|:--------:|:-------:|:----------:|:--------:|:-----:|:--------:|:----:|:------:|:------:|:------:|
| [AppVeyor]( https://www.appveyor.com/docs/environment-variables) | `appveyor` ||||||||||||
| [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html) | `bamboo` ||||||||||||
| [Bitbucket](https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html) | `bitbucket` ||||||||||||
| [Bitrise](http://devcenter.bitrise.io/faq/available-environment-variables/#exposed-by-bitriseio) | `bitrise` ||||||||||||
| [Buildkite](https://buildkite.com/docs/builds/environment-variables) | `buildkite` ||||||||||||
| [CircleCI](https://circleci.com/docs/1.0/environment-variables) | `circleci` ||||||||||||
| [Codeship](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables) | `codeship` ||||||||||||
| [Drone](http://readme.drone.io/0.5/usage/environment-reference) | `drone` ||||||||||||
| [Gitlab CI/CD](https://docs.gitlab.com/ce/ci/variables/README.html) | `gitlab` ||||||||||||
| [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project) | `jenkins` ||||||||||||
| [Semaphore](https://semaphoreci.com/docs/available-environment-variables.html) | `semaphore` ||||||||||||
| [Shippable](http://docs.shippable.com/ci/env-vars/#stdEnv) | `shippable` ||||||||||||
| [TeamCity](https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters) | `teamcity` ||||||||||||
| [Travis CI](https://docs.travis-ci.com/user/environment-variables) | `travis` ||||||||||||
| [Wercker](http://devcenter.wercker.com/docs/environment-variables/available-env-vars#hs_cos_wrapper_name) | `wercker` ||||||||||||

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.
1 change: 1 addition & 0 deletions lib/appveyor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'Appveyor',
service: 'appveyor',
commit: process.env.APPVEYOR_REPO_COMMIT,
build: process.env.APPVEYOR_BUILD_NUMBER,
Expand Down
1 change: 1 addition & 0 deletions lib/bamboo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
},
configuration() {
return {
name: 'Bamboo',
service: 'bamboo',
commit: process.env.bamboo_planRepository_1_revision,
build: process.env.bamboo_buildNumber,
Expand Down
1 change: 1 addition & 0 deletions lib/bitbucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'Bitbucket Pipelines',
service: 'bitbucket',
commit: process.env.BITBUCKET_COMMIT,
build: process.env.BITBUCKET_BUILD_NUMBER,
Expand Down
1 change: 1 addition & 0 deletions lib/bitrise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'Bitrise',
service: 'bitrise',
commit: process.env.BITRISE_GIT_COMMIT,
build: process.env.BITRISE_BUILD_NUMBER,
Expand Down
1 change: 1 addition & 0 deletions lib/buildkite.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'Buildkite',
service: 'buildkite',
build: process.env.BUILDKITE_BUILD_NUMBER,
buildUrl: process.env.BUILDKITE_BUILD_URL,
Expand Down
1 change: 1 addition & 0 deletions lib/circleci.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'CircleCI',
service: 'circleci',
build: process.env.CIRCLE_BUILD_NUM,
buildUrl: process.env.CIRCLE_BUILD_URL,
Expand Down
1 change: 1 addition & 0 deletions lib/codeship.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'Codeship',
service: 'codeship',
build: process.env.CI_BUILD_NUMBER,
buildUrl: process.env.CI_BUILD_URL,
Expand Down
1 change: 1 addition & 0 deletions lib/drone.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'Drone',
service: 'drone',
commit: process.env.DRONE_COMMIT_SHA,
build: process.env.DRONE_BUILD_NUMBER,
Expand Down
1 change: 1 addition & 0 deletions lib/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'GitLab CI/CD',
service: 'gitlab',
commit: process.env.CI_COMMIT_SHA,
build: process.env.CI_JOB_NAME,
Expand Down
1 change: 1 addition & 0 deletions lib/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
},
configuration() {
return {
name: 'Jenkins',
service: 'jenkins',
commit: process.env.ghprbActualCommit || process.env.GIT_COMMIT || git.head(),
branch:
Expand Down
1 change: 1 addition & 0 deletions lib/semaphore.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
},
configuration() {
return {
name: 'Semaphore',
service: 'semaphore',
commit: git.head(),
build: process.env.SEMAPHORE_BUILD_NUMBER,
Expand Down
1 change: 1 addition & 0 deletions lib/shippable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'Shippable',
service: 'shippable',
commit: process.env.COMMIT,
build: process.env.BUILD_NUMBER,
Expand Down
1 change: 1 addition & 0 deletions lib/teamcity.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
configuration() {
return Object.assign(
{
name: 'TeamCity',
service: 'teamcity',
commit: process.env.BUILD_VCS_NUMBER,
build: process.env.BUILD_NUMBER,
Expand Down
1 change: 1 addition & 0 deletions lib/travis.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'Travis CI',
service: 'travis',
commit: process.env.TRAVIS_COMMIT,
build: process.env.TRAVIS_BUILD_NUMBER,
Expand Down
1 change: 1 addition & 0 deletions lib/wercker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
},
configuration() {
return {
name: 'Wercker',
service: 'wercker',
commit: process.env.WERCKER_GIT_COMMIT,
build: process.env.WERCKER_MAIN_PIPELINE_STARTED,
Expand Down
2 changes: 2 additions & 0 deletions test/appveyor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test('Push', t => {
delete process.env.APPVEYOR_PULL_REQUEST_NUMBER;

t.deepEqual(appveyor.configuration(), {
name: 'Appveyor',
service: 'appveyor',
commit: '5678',
build: '91011',
Expand Down Expand Up @@ -42,6 +43,7 @@ test('PR', t => {
process.env.APPVEYOR_REPO_BRANCH = 'master';

t.deepEqual(appveyor.configuration(), {
name: 'Appveyor',
service: 'appveyor',
commit: '5678',
build: '91011',
Expand Down
1 change: 1 addition & 0 deletions test/bamboo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('Push', t => {
process.env.bamboo_buildResultsUrl = 'https://server.com/buildresult';

t.deepEqual(bamboo.configuration(), {
name: 'Bamboo',
service: 'bamboo',
commit: '5678',
build: '91011',
Expand Down
2 changes: 2 additions & 0 deletions test/bitbucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ test('Push', t => {
process.env.BITBUCKET_CLONE_DIR = '/';

t.deepEqual(bitbucket.configuration(), {
name: 'Bitbucket Pipelines',
service: 'bitbucket',
commit: 'b5ce5ce',
build: '1964',
Expand All @@ -27,6 +28,7 @@ test('PR', t => {
process.env.BITBUCKET_CLONE_DIR = '/';

t.deepEqual(bitbucket.configuration(), {
name: 'Bitbucket Pipelines',
service: 'bitbucket',
commit: 'b5ce5ce',
build: '1964',
Expand Down
2 changes: 2 additions & 0 deletions test/bitrise.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('Push', t => {
process.env.BITRISE_APP_SLUG = 'owner/repo';

t.deepEqual(bitrise.configuration(), {
name: 'Bitrise',
service: 'bitrise',
commit: '5678',
build: '91011',
Expand All @@ -32,6 +33,7 @@ test('PR', t => {
process.env.BITRISE_APP_SLUG = 'owner/repo';

t.deepEqual(bitrise.configuration(), {
name: 'Bitrise',
service: 'bitrise',
commit: '5678',
build: '91011',
Expand Down
2 changes: 2 additions & 0 deletions test/buildkite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test('Push', t => {
process.env.BUILDKITE_PROJECT_SLUG = 'repo';

t.deepEqual(buildkite.configuration(), {
name: 'Buildkite',
service: 'buildkite',
commit: '5678',
build: '91011',
Expand All @@ -36,6 +37,7 @@ test('PR', t => {
process.env.BUILDKITE_PROJECT_SLUG = 'repo';

t.deepEqual(buildkite.configuration(), {
name: 'Buildkite',
service: 'buildkite',
commit: '5678',
build: '91011',
Expand Down
2 changes: 2 additions & 0 deletions test/circleci.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test('Push', t => {
delete process.env.CI_PULL_REQUEST;

t.deepEqual(circle.configuration(), {
name: 'CircleCI',
service: 'circleci',
commit: '5678',
build: '1234',
Expand All @@ -36,6 +37,7 @@ test('PR', t => {
process.env.CI_PULL_REQUEST = 'uri/pr/10';

t.deepEqual(circle.configuration(), {
name: 'CircleCI',
service: 'circleci',
commit: '5678',
build: '1234',
Expand Down
1 change: 1 addition & 0 deletions test/codeship.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test('Push', t => {
process.env.CI_REPO_NAME = 'owner/repo';

t.deepEqual(codeship.configuration(), {
name: 'Codeship',
service: 'codeship',
commit: '5678',
build: '91011',
Expand Down
2 changes: 2 additions & 0 deletions test/drone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ test('Push', t => {
delete process.env.DRONE_BUILD_EVENT;

t.deepEqual(drone.configuration(), {
name: 'Drone',
service: 'drone',
commit: '5678',
build: '91011',
Expand All @@ -36,6 +37,7 @@ test('PR', t => {
process.env.DRONE_REPO_NAME = 'repo';

t.deepEqual(drone.configuration(), {
name: 'Drone',
service: 'drone',
commit: '5678',
build: '91011',
Expand Down
1 change: 1 addition & 0 deletions test/gitlab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ test('Push', t => {
process.env.CI_PROJECT_DIR = '/';

t.deepEqual(gitlab.configuration(), {
name: 'GitLab CI/CD',
service: 'gitlab',
commit: '5678',
build: 'job_name',
Expand Down
3 changes: 3 additions & 0 deletions test/jenkins.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test('Push', t => {
delete process.env.ghprbPullId;

t.deepEqual(jenkins.configuration(), {
name: 'Jenkins',
service: 'jenkins',
commit: '5678',
build: '91011',
Expand All @@ -40,6 +41,7 @@ test('PR', t => {
delete process.env.ghprbPullId;

t.deepEqual(jenkins.configuration(), {
name: 'Jenkins',
service: 'jenkins',
commit: '5678',
build: '91011',
Expand All @@ -65,6 +67,7 @@ test('PR (PR builder)', t => {
delete process.env.CHANGE_ID;

t.deepEqual(jenkins.configuration(), {
name: 'Jenkins',
service: 'jenkins',
commit: '5678',
build: '91011',
Expand Down
2 changes: 2 additions & 0 deletions test/semaphore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test.serial('Push', async t => {
delete process.env.PULL_REQUEST_NUMBER;

t.deepEqual(semaphore.configuration(), {
name: 'Semaphore',
service: 'semaphore',
commit,
build: '91011',
Expand All @@ -45,6 +46,7 @@ test.serial('PR', async t => {
process.env.SEMAPHORE_REPO_SLUG = 'owner/repo';

t.deepEqual(semaphore.configuration(), {
name: 'Semaphore',
service: 'semaphore',
commit,
build: '91011',
Expand Down
2 changes: 2 additions & 0 deletions test/shippable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test('Push', t => {
delete process.env.BASE_BRANCH;

t.deepEqual(shippable.configuration(), {
name: 'Shippable',
service: 'shippable',
commit: '5678',
build: '91011',
Expand Down Expand Up @@ -42,6 +43,7 @@ test('PR', t => {
delete process.env.BRANCH;

t.deepEqual(shippable.configuration(), {
name: 'Shippable',
service: 'shippable',
commit: '5678',
build: '91011',
Expand Down
2 changes: 2 additions & 0 deletions test/teamcity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test('Push', t => {
fs.writeFileSync(propertiesFile, properties.join('\n') + '\n');

t.deepEqual(teamcity.configuration(), {
name: 'TeamCity',
service: 'teamcity',
commit: '5678',
build: '91011',
Expand All @@ -33,6 +34,7 @@ test('Push (no properties file)', t => {
delete process.env.TEAMCITY_BUILD_PROPERTIES_FILE;

t.deepEqual(teamcity.configuration(), {
name: 'TeamCity',
service: 'teamcity',
commit: '5678',
build: '91011',
Expand Down
2 changes: 2 additions & 0 deletions test/travis.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ test('Push', t => {
process.env.TRAVIS_REPO_SLUG = 'owner/repo';

t.deepEqual(travis.configuration(), {
name: 'Travis CI',
service: 'travis',
commit: '5678',
build: '91011',
Expand All @@ -35,6 +36,7 @@ test('PR', t => {
process.env.TRAVIS_REPO_SLUG = 'owner/repo';

t.deepEqual(travis.configuration(), {
name: 'Travis CI',
service: 'travis',
commit: '5678',
build: '91011',
Expand Down
1 change: 1 addition & 0 deletions test/wercker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ test('Push', t => {
process.env.WERCKER_GIT_REPOSITORY = 'repo';

t.deepEqual(wercker.configuration(), {
name: 'Wercker',
service: 'wercker',
commit: '5678',
build: '123456',
Expand Down

0 comments on commit 4d3d673

Please sign in to comment.