From 0144b3a23359f0b1822ca43231101bfd56034bd7 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Thu, 4 Jan 2018 07:40:33 +1000 Subject: [PATCH] feat: added bamboo as another ci service --- README.md | 1 + index.js | 1 + lib/bamboo.js | 20 ++++++++++++++++++++ package.json | 1 + test/bamboo.test.js | 21 +++++++++++++++++++++ test/index.test.js | 10 ++++++++++ 6 files changed, 54 insertions(+) create mode 100644 lib/bamboo.js create mode 100644 test/bamboo.test.js diff --git a/README.md b/README.md index f064751..7dd3617 100644 --- a/README.md +++ b/README.md @@ -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` | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | diff --git a/index.js b/index.js index b7718af..e6ca34f 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,7 @@ const services = { drone: require('./lib/drone'), buildkite: require('./lib/buildkite'), gitlab: require('./lib/gitlab'), + bamboo: require('./lib/bamboo'), }; module.exports = () => { diff --git a/lib/bamboo.js b/lib/bamboo.js new file mode 100644 index 0000000..b2e8c47 --- /dev/null +++ b/lib/bamboo.js @@ -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 */ + }; + }, +}; diff --git a/package.json b/package.json index ea008c8..6c6756e 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "homepage": "https://github.com/pvdlg/env-ci#readme", "keywords": [ "appveyor", + "bamboo", "buildkite", "ci", "circle", diff --git a/test/bamboo.test.js b/test/bamboo.test.js new file mode 100644 index 0000000..140def9 --- /dev/null +++ b/test/bamboo.test.js @@ -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', + }); +}); diff --git a/test/index.test.js b/test/index.test.js index 5e0485d..a311aad 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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(() => { @@ -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();