Skip to content

Commit

Permalink
feat: added bamboo as another ci service
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr authored and pvdlg committed Jan 3, 2018
1 parent b950b1a commit 0144b3a
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const {isCi, service, commit, build, branch, job, pr, isPr, slug, root} = envCi(
| CI Service | `service` | `isCi` | `commit` | `build` | `branch` | `job` | `pr` | `isPr` | `slug` | `root` |
|-----------------------------------------------------------------------------------------------------------|:-----------:|:------:|:--------:|:-------:|:--------:|:-----:|:----:|:------:|:------:|:------:|
| [AppVeyor]( https://www.appveyor.com/docs/environment-variables) | `appveyor` ||||||||||
| [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html) | `bamboo` ||||||||||
| [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` ||||||||||
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const services = {
drone: require('./lib/drone'),
buildkite: require('./lib/buildkite'),
gitlab: require('./lib/gitlab'),
bamboo: require('./lib/bamboo'),
};

module.exports = () => {
Expand Down
20 changes: 20 additions & 0 deletions lib/bamboo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html

module.exports = {
detect() {
// eslint-disable-next-line camelcase
return Boolean(process.env.bamboo_agentId);
},
configuration() {
return {
service: 'bamboo',
/* eslint-disable camelcase */
commit: process.env.bamboo_planRepository_1_revision,
build: process.env.bamboo_buildNumber,
branch: process.env.bamboo_planRepository_1_branchName,
job: process.env.bamboo_buildKey,
root: process.env.bamboo_build_working_directory,
/* eslint-enable camelcase */
};
},
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"homepage": "https://github.com/pvdlg/env-ci#readme",
"keywords": [
"appveyor",
"bamboo",
"buildkite",
"ci",
"circle",
Expand Down
21 changes: 21 additions & 0 deletions test/bamboo.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import test from 'ava';
import bamboo from '../lib/bamboo';

test('Push', t => {
/* eslint-disable camelcase */
process.env.bamboo_planRepository_1_revision = 'some commit hash';
process.env.bamboo_buildNumber = 'some build number';
process.env.bamboo_planRepository_1_branchName = 'some branch name';
process.env.bamboo_buildKey = 'some job number';
process.env.bamboo_build_working_directory = '/some/working/dir';
/* eslint-enable camelcase */

t.deepEqual(bamboo.configuration(), {
service: 'bamboo',
commit: 'some commit hash',
build: 'some build number',
branch: 'some branch name',
root: '/some/working/dir',
job: 'some job number',
});
});
10 changes: 10 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ test.beforeEach(() => {
delete process.env.SHIPPABLE;
delete process.env.TRAVIS;
delete process.env.WERCKER_MAIN_PIPELINE_STARTED;
delete process.env.bamboo_agentId;
});

test.afterEach.always(() => {
Expand Down Expand Up @@ -118,6 +119,15 @@ test.serial('Wercker', t => {
t.is(env.service, 'wercker');
});

test.serial('Bamboo', t => {
// eslint-disable-next-line camelcase
process.env.bamboo_agentId = 'some bamboo agent id';

const env = m();
t.is(env.isCi, true);
t.is(env.service, 'bamboo');
});

test.serial('Unknown CI and Git repository', async t => {
process.env.CI = 'true';
await gitRepo();
Expand Down

0 comments on commit 0144b3a

Please sign in to comment.