Imported Upstream version 1.0.0
Siddhesh Rane
7 years ago
0 | node_modules |
0 | The MIT License (MIT) | |
1 | ||
2 | Copyright (c) 2016 Thomas Watson Steen | |
3 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | of this software and associated documentation files (the "Software"), to deal | |
6 | in the Software without restriction, including without limitation the rights | |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | copies of the Software, and to permit persons to whom the Software is | |
9 | furnished to do so, subject to the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in all | |
12 | copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
20 | SOFTWARE. |
0 | # ci-info | |
1 | ||
2 | Get details about the current Continuous Integration environment. | |
3 | ||
4 | Please [open an issue](https://github.com/watson/ci-info/issues) if your | |
5 | CI server isn't properly detected :) | |
6 | ||
7 | [![Build status](https://travis-ci.org/watson/ci-info.svg?branch=master)](https://travis-ci.org/watson/ci-info) | |
8 | [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) | |
9 | ||
10 | ## Installation | |
11 | ||
12 | ``` | |
13 | npm install ci-info --save | |
14 | ``` | |
15 | ||
16 | ## Usage | |
17 | ||
18 | ```js | |
19 | var ci = require('ci-info') | |
20 | ||
21 | if (ci.isCI) { | |
22 | console.log('The name of the CI server is:', ci.name) | |
23 | } else { | |
24 | console.log('This program is not running on a CI server') | |
25 | } | |
26 | ``` | |
27 | ||
28 | ## Supported CI tools | |
29 | ||
30 | Officially supported CI servers: | |
31 | ||
32 | - [Travis CI](http://travis-ci.org) | |
33 | - [CircleCI](http://circleci.com) | |
34 | - [Jenkins CI](https://jenkins-ci.org) | |
35 | - [Hudson](http://hudson-ci.org) | |
36 | - [Bamboo](https://www.atlassian.com/software/bamboo) by Atlassian | |
37 | - [TeamCity](https://www.jetbrains.com/teamcity/) by JetBrains | |
38 | - [Team Foundation Server](https://www.visualstudio.com/en-us/products/tfs-overview-vs.aspx) by Microsoft | |
39 | - [GitLab CI](https://about.gitlab.com/gitlab-ci/) | |
40 | - [Codeship](https://codeship.com) | |
41 | - [Drone](https://drone.io) | |
42 | - [Magnum CI](https://magnum-ci.com) | |
43 | - [Semaphore](https://semaphoreci.com) | |
44 | - [AppVeyor](http://www.appveyor.com) | |
45 | - [Buildkite](https://buildkite.com) | |
46 | - [TaskCluster](http://docs.taskcluster.net) | |
47 | - [GoCD](https://www.go.cd/) | |
48 | - [Bitbucket Pipelines](https://bitbucket.org/product/features/pipelines) | |
49 | ||
50 | ## API | |
51 | ||
52 | ### `ci.name` | |
53 | ||
54 | A string. Will contain the name of the CI server the code is running on. | |
55 | If not CI server is detected, it will be `null`. | |
56 | ||
57 | Don't depend on the value of this string not to change for a specific | |
58 | vendor. If you find your self writing `ci.name === 'Travis CI'`, you | |
59 | most likely want to use `ci.TRAVIS` instead. | |
60 | ||
61 | ### `ci.isCI` | |
62 | ||
63 | A boolean. Will be `true` if the code is running on a CI server. | |
64 | Otherwise `false`. | |
65 | ||
66 | Some CI servers not listed here might still trigger the `ci.isCI` | |
67 | boolean to be set to `true` if they use certain vendor neutral | |
68 | environment variables. In those cases `ci.name` will be `null` and no | |
69 | vendor specific boolean will be set to `true`. | |
70 | ||
71 | ### `ci.<VENDOR-CONSTANT>` | |
72 | ||
73 | The following vendor specific boolean constants are exposed. A constant | |
74 | will be `true` if the code is determined to run on the given CI server. | |
75 | Otherwise `false`. | |
76 | ||
77 | - `ci.TRAVIS` | |
78 | - `ci.CIRCLE` | |
79 | - `ci.GITLAB` | |
80 | - `ci.APPVEYOR` | |
81 | - `ci.CODESHIP` | |
82 | - `ci.DRONE` | |
83 | - `ci.MAGNUM` | |
84 | - `ci.SEMAPHORE` | |
85 | - `ci.JENKINS` | |
86 | - `ci.BAMBOO` | |
87 | - `ci.TFS` (Team Foundation Server) | |
88 | - `ci.TEAMCITY` | |
89 | - `ci.BUILDKITE` | |
90 | - `ci.HUDSON` | |
91 | - `ci.TASKCLUSTER` | |
92 | - `ci.GOCD` | |
93 | - `ci.BITBUCKET` | |
94 | ||
95 | ## License | |
96 | ||
97 | MIT |
0 | 'use strict' | |
1 | ||
2 | var env = process.env | |
3 | ||
4 | var vendors = [ | |
5 | // Constant, Name, Envs | |
6 | ['TRAVIS', 'Travis CI', 'TRAVIS'], | |
7 | ['CIRCLE', 'CircleCI', 'CIRCLECI'], | |
8 | ['GITLAB', 'GitLab CI', 'GITLAB_CI'], | |
9 | ['APPVEYOR', 'AppVeyor', 'APPVEYOR'], | |
10 | ['CODESHIP', 'Codeship', {CI_NAME: 'codeship'}], | |
11 | ['DRONE', 'Drone', 'DRONE'], | |
12 | ['MAGNUM', 'Magnum CI', 'MAGNUM'], | |
13 | ['SEMAPHORE', 'Semaphore', 'SEMAPHORE'], | |
14 | ['JENKINS', 'Jenkins', 'JENKINS_URL'], | |
15 | ['BAMBOO', 'Bamboo', 'bamboo_planKey'], | |
16 | ['TFS', 'Team Foundation Server', 'TF_BUILD'], | |
17 | ['TEAMCITY', 'TeamCity', 'TEAMCITY_VERSION'], | |
18 | ['BUILDKITE', 'Buildkite', 'BUILDKITE'], | |
19 | ['HUDSON', 'Hudsun', 'HUDSON_URL'], | |
20 | ['TASKCLUSTER', 'TaskCluster', 'TASK_ID', 'RUN_ID'], | |
21 | ['GOCD', 'GoCD', 'GO_PIPELINE_LABEL'], | |
22 | ['BITBUCKET', 'Bitbucket Pipelines', 'BITBUCKET_COMMIT'] | |
23 | ] | |
24 | ||
25 | exports.name = null | |
26 | ||
27 | vendors.forEach(function (vendor) { | |
28 | var constant = vendor.shift() | |
29 | var name = vendor.shift() | |
30 | var isCI = vendor.every(function (obj) { | |
31 | if (typeof obj === 'string') return !!env[obj] | |
32 | return Object.keys(obj).every(function (k) { | |
33 | return env[k] === obj[k] | |
34 | }) | |
35 | }) | |
36 | exports[constant] = isCI | |
37 | if (isCI) exports.name = name | |
38 | }) | |
39 | ||
40 | exports.isCI = !!( | |
41 | env.CI || // Travis CI, CircleCI, Gitlab CI, Appveyor, CodeShip | |
42 | env.CONTINUOUS_INTEGRATION || // Travis CI | |
43 | env.BUILD_NUMBER || // Jenkins, TeamCity | |
44 | exports.name || | |
45 | false | |
46 | ) |
0 | { | |
1 | "name": "ci-info", | |
2 | "version": "1.0.0", | |
3 | "description": "Get details about the current Continuous Integration environment", | |
4 | "main": "index.js", | |
5 | "dependencies": {}, | |
6 | "devDependencies": { | |
7 | "clear-require": "^1.0.1", | |
8 | "standard": "^8.4.0" | |
9 | }, | |
10 | "scripts": { | |
11 | "test": "standard && node test.js" | |
12 | }, | |
13 | "repository": { | |
14 | "type": "git", | |
15 | "url": "https://github.com/watson/ci-info.git" | |
16 | }, | |
17 | "keywords": [ | |
18 | "ci", | |
19 | "continuous", | |
20 | "integration", | |
21 | "test", | |
22 | "detect" | |
23 | ], | |
24 | "author": "Thomas Watson Steen <w@tson.dk> (https://twitter.com/wa7son)", | |
25 | "license": "MIT", | |
26 | "bugs": { | |
27 | "url": "https://github.com/watson/ci-info/issues" | |
28 | }, | |
29 | "homepage": "https://github.com/watson/ci-info", | |
30 | "coordinates": [ | |
31 | 55.68768499999999, | |
32 | 12.5955698 | |
33 | ] | |
34 | } |
0 | 'use strict' | |
1 | ||
2 | var assert = require('assert') | |
3 | var clearRequire = require('clear-require') | |
4 | ||
5 | // Known CI | |
6 | process.env.TRAVIS = 'true' | |
7 | var ci = require('./') | |
8 | ||
9 | assert.equal(ci.isCI, true) | |
10 | assert.equal(ci.name, 'Travis CI') | |
11 | assert.equal(ci.TRAVIS, true) | |
12 | assert.equal(ci.CIRCLE, false) | |
13 | assert.equal(ci.GITLAB, false) | |
14 | assert.equal(ci.APPVEYOR, false) | |
15 | assert.equal(ci.CODESHIP, false) | |
16 | assert.equal(ci.DRONE, false) | |
17 | assert.equal(ci.MAGNUM, false) | |
18 | assert.equal(ci.SEMAPHORE, false) | |
19 | assert.equal(ci.JENKINS, false) | |
20 | assert.equal(ci.BAMBOO, false) | |
21 | assert.equal(ci.TFS, false) | |
22 | assert.equal(ci.TEAMCITY, false) | |
23 | assert.equal(ci.BUILDKITE, false) | |
24 | assert.equal(ci.HUDSON, false) | |
25 | assert.equal(ci.TASKCLUSTER, false) | |
26 | assert.equal(ci.GOCD, false) | |
27 | assert.equal(ci.BITBUCKET, false) | |
28 | ||
29 | // Not CI | |
30 | delete process.env.CI | |
31 | delete process.env.CONTINUOUS_INTEGRATION | |
32 | delete process.env.BUILD_NUMBER | |
33 | delete process.env.TRAVIS | |
34 | clearRequire('./') | |
35 | ci = require('./') | |
36 | ||
37 | assert.equal(ci.isCI, false) | |
38 | assert.equal(ci.name, undefined) | |
39 | assert.equal(ci.TRAVIS, false) | |
40 | assert.equal(ci.CIRCLE, false) | |
41 | assert.equal(ci.GITLAB, false) | |
42 | assert.equal(ci.APPVEYOR, false) | |
43 | assert.equal(ci.CODESHIP, false) | |
44 | assert.equal(ci.DRONE, false) | |
45 | assert.equal(ci.MAGNUM, false) | |
46 | assert.equal(ci.SEMAPHORE, false) | |
47 | assert.equal(ci.JENKINS, false) | |
48 | assert.equal(ci.BAMBOO, false) | |
49 | assert.equal(ci.TFS, false) | |
50 | assert.equal(ci.TEAMCITY, false) | |
51 | assert.equal(ci.BUILDKITE, false) | |
52 | assert.equal(ci.HUDSON, false) | |
53 | assert.equal(ci.TASKCLUSTER, false) | |
54 | assert.equal(ci.GOCD, false) | |
55 | assert.equal(ci.BITBUCKET, false) | |
56 | ||
57 | // Unknown CI | |
58 | process.env.CI = 'true' | |
59 | clearRequire('./') | |
60 | ci = require('./') | |
61 | ||
62 | assert.equal(ci.isCI, true) | |
63 | assert.equal(ci.name, undefined) | |
64 | assert.equal(ci.TRAVIS, false) | |
65 | assert.equal(ci.CIRCLE, false) | |
66 | assert.equal(ci.GITLAB, false) | |
67 | assert.equal(ci.APPVEYOR, false) | |
68 | assert.equal(ci.CODESHIP, false) | |
69 | assert.equal(ci.DRONE, false) | |
70 | assert.equal(ci.MAGNUM, false) | |
71 | assert.equal(ci.SEMAPHORE, false) | |
72 | assert.equal(ci.JENKINS, false) | |
73 | assert.equal(ci.BAMBOO, false) | |
74 | assert.equal(ci.TFS, false) | |
75 | assert.equal(ci.TEAMCITY, false) | |
76 | assert.equal(ci.BUILDKITE, false) | |
77 | assert.equal(ci.HUDSON, false) | |
78 | assert.equal(ci.TASKCLUSTER, false) | |
79 | assert.equal(ci.GOCD, false) | |
80 | assert.equal(ci.BITBUCKET, false) |