Skip to content

Commit

Permalink
feat: add Bitbucket support
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Durrans authored and pvdlg committed Mar 30, 2018
1 parent ea44060 commit 158892c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 16 deletions.
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,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` ||||||||||||
| [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 | `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` ||||||||||||

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 index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const git = require('./lib/git');
const services = {
appveyor: require('./lib/appveyor'),
bamboo: require('./lib/bamboo'),
bitbucket: require('./lib/bitbucket'),
bitrise: require('./lib/bitrise'),
buildkite: require('./lib/buildkite'),
circleci: require('./lib/circleci'),
Expand Down
20 changes: 20 additions & 0 deletions lib/bitbucket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html

module.exports = {
detect() {
return Boolean(process.env.BITBUCKET_BUILD_NUMBER);
},
configuration() {
return {
service: 'bitbucket',
commit: process.env.BITBUCKET_COMMIT,
build: process.env.BITBUCKET_BUILD_NUMBER,
buildUrl: `https://bitbucket.org/${process.env.BITBUCKET_REPO_SLUG}/addon/pipelines/home#!/results/${
process.env.BITBUCKET_BUILD_NUMBER
}`,
branch: process.env.BITBUCKET_BRANCH,
slug: process.env.BITBUCKET_REPO_SLUG,
root: process.env.BITBUCKET_CLONE_DIR,
};
},
};
38 changes: 38 additions & 0 deletions test/bitbucket.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import test from 'ava';
import bitbucket from '../lib/bitbucket';

test('Push', t => {
process.env.BITBUCKET_COMMIT = 'b5ce5ce';
process.env.BITBUCKET_BUILD_NUMBER = '1964';
process.env.BITBUCKET_BRANCH = 'master';
process.env.BITBUCKET_REPO_SLUG = 'owner/repo';
process.env.BITBUCKET_CLONE_DIR = '/';

t.deepEqual(bitbucket.configuration(), {
service: 'bitbucket',
commit: 'b5ce5ce',
build: '1964',
buildUrl: 'https://bitbucket.org/owner/repo/addon/pipelines/home#!/results/1964',
branch: 'master',
slug: 'owner/repo',
root: '/',
});
});

test('PR', t => {
process.env.BITBUCKET_COMMIT = 'b5ce5ce';
process.env.BITBUCKET_BUILD_NUMBER = '1964';
process.env.BITBUCKET_BRANCH = 'master';
process.env.BITBUCKET_REPO_SLUG = 'owner/repo';
process.env.BITBUCKET_CLONE_DIR = '/';

t.deepEqual(bitbucket.configuration(), {
service: 'bitbucket',
commit: 'b5ce5ce',
build: '1964',
buildUrl: 'https://bitbucket.org/owner/repo/addon/pipelines/home#!/results/1964',
branch: 'master',
slug: 'owner/repo',
root: '/',
});
});
9 changes: 9 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const cwd = process.cwd();
test.beforeEach(() => {
delete process.env.CI;
delete process.env.APPVEYOR;
delete process.env.BITBUCKET_BUILD_NUMBER;
delete process.env.BUILDKITE;
delete process.env.CIRCLECI;
delete process.env.CI_NAME;
Expand Down Expand Up @@ -36,6 +37,14 @@ test.serial('Appveyor', t => {
t.is(env.service, 'appveyor');
});

test.serial('Bitbucket', t => {
process.env.BITBUCKET_BUILD_NUMBER = '123456';

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

test.serial('Buildkite', t => {
process.env.BUILDKITE = 'true';

Expand Down

0 comments on commit 158892c

Please sign in to comment.