Skip to content

Commit

Permalink
feat: add buildUrl and jobUrl properties
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Feb 4, 2018
1 parent acd3f54 commit bedc975
Show file tree
Hide file tree
Showing 21 changed files with 100 additions and 42 deletions.
58 changes: 30 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,38 @@ const {isCi, service, commit, build, branch, job, pr, isPr, slug, root} = envCi(

## Variables

| Variable | Description |
|-----------|-----------------------------------------------------------------------------------|
| `isCi` | `true` is running on a CI, `false` otherwise |
| `service` | CI service name |
| `commit` | Commit sha that triggered the CI build |
| `build` | CI service build number |
| `branch` | Git branch being built or targeted by a pull request |
| `job` | CI service job number |
| `pr` | Pull Request number |
| `isPr` | `true` is the build has been triggered by a Pull Request, `false` otherwise |
| `slug` | The slug (in form: owner_name/repo_name) of the repository currently being built. |
| `root` | The path to the directory where the repository is being built |
| Variable | Description |
|------------|-----------------------------------------------------------------------------------|
| `isCi` | `true` is running on a CI, `false` otherwise |
| `service` | CI service name |
| `commit` | Commit sha that triggered the CI build |
| `build` | CI service build number |
| `buildUrl` | Link to the CI service build |
| `branch` | Git branch being built or targeted by a pull request |
| `job` | CI service job number |
| `jobUrl` | Link to the CI service job |
| `pr` | Pull Request number |
| `isPr` | `true` is the build has been triggered by a Pull Request, `false` otherwise |
| `slug` | The slug (in form: owner_name/repo_name) of the repository currently being built. |
| `root` | The path to the directory where the repository is being built |

## Supported CI

| 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` ||||| |||||
| [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` |||| | || |||||
| [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.
6 changes: 6 additions & 0 deletions lib/appveyor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ module.exports = {
service: 'appveyor',
commit: process.env.APPVEYOR_REPO_COMMIT,
build: process.env.APPVEYOR_BUILD_NUMBER,
buildUrl: `https://ci.appveyor.com/project/${process.env.APPVEYOR_PROJECT_SLUG}/build/${
process.env.APPVEYOR_BUILD_VERSION
}`,
branch: process.env.APPVEYOR_REPO_BRANCH,
job: process.env.APPVEYOR_JOB_NUMBER,
jobUrl: `https://ci.appveyor.com/project/${process.env.APPVEYOR_PROJECT_SLUG}/build/job/${
process.env.APPVEYOR_JOB_ID
}`,
pr: process.env.APPVEYOR_PULL_REQUEST_NUMBER,
isPr: Boolean(process.env.APPVEYOR_PULL_REQUEST_NUMBER),
slug: process.env.APPVEYOR_REPO_NAME,
Expand Down
1 change: 1 addition & 0 deletions lib/bamboo.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
/* eslint-disable camelcase */
commit: process.env.bamboo_planRepository_1_revision,
build: process.env.bamboo_buildNumber,
buildUrl: process.env.bamboo_buildResultsUrl,
branch: process.env.bamboo_planRepository_1_branchName,
job: process.env.bamboo_buildKey,
root: process.env.bamboo_build_working_directory,
Expand Down
3 changes: 2 additions & 1 deletion lib/bitrise.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// http://devcenter.bitrise.io/faq/available-environment-variables/
// http://devcenter.bitrise.io/faq/available-environment-variables

module.exports = {
detect() {
Expand All @@ -9,6 +9,7 @@ module.exports = {
service: 'bitrise',
commit: process.env.BITRISE_GIT_COMMIT,
build: process.env.BITRISE_BUILD_NUMBER,
buildUrl: process.env.BITRISE_BUILD_URL,
branch: process.env.BITRISE_GIT_BRANCH,
pr: process.env.BITRISE_PULL_REQUEST === 'false' ? undefined : process.env.BITRISE_PULL_REQUEST,
isPr: process.env.BITRISE_PULL_REQUEST && process.env.BITRISE_PULL_REQUEST !== 'false',
Expand Down
1 change: 1 addition & 0 deletions lib/buildkite.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
return {
service: 'buildkite',
build: process.env.BUILDKITE_BUILD_NUMBER,
buildUrl: process.env.BUILDKITE_BUILD_URL,
commit: process.env.BUILDKITE_COMMIT,
branch: process.env.BUILDKITE_BRANCH,
slug: `${process.env.BUILDKITE_ORGANIZATION_SLUG}/${process.env.BUILDKITE_PROJECT_SLUG}`,
Expand Down
3 changes: 2 additions & 1 deletion lib/circleci.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = {
configuration() {
return {
service: 'circleci',
build: `${process.env.CIRCLE_BUILD_NUM}.${process.env.CIRCLE_NODE_INDEX}`,
build: process.env.CIRCLE_BUILD_NUM,
buildUrl: process.env.CIRCLE_BUILD_URL,
job: `${process.env.CIRCLE_BUILD_NUM}.${process.env.CIRCLE_NODE_INDEX}`,
commit: process.env.CIRCLE_SHA1,
branch: process.env.CIRCLE_BRANCH,
Expand Down
1 change: 1 addition & 0 deletions lib/codeship.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
return {
service: 'codeship',
build: process.env.CI_BUILD_NUMBER,
buildUrl: process.env.CI_BUILD_URL,
commit: process.env.CI_COMMIT_ID,
branch: process.env.CI_BRANCH,
slug: process.env.CI_REPO_NAME,
Expand Down
2 changes: 2 additions & 0 deletions lib/gitlab.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ module.exports = {
service: 'gitlab',
commit: process.env.CI_COMMIT_SHA,
build: process.env.CI_JOB_NAME,
buildUrl: `${process.env.CI_PROJECT_URL}/pipelines/${process.env.CI_PIPELINE_ID}`,
job: process.env.CI_JOB_STAGE,
jobUrl: `${process.env.CI_PROJECT_URL}/-/jobs/${process.env.CI_JOB_ID}`,
branch: process.env.CI_COMMIT_REF_NAME,
slug: process.env.CI_PROJECT_PATH,
root: process.env.CI_PROJECT_DIR,
Expand Down
1 change: 1 addition & 0 deletions lib/jenkins.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
commit: process.env.ghprbActualCommit || process.env.GIT_COMMIT || git.head(),
branch: process.env.ghprbSourceBranch || process.env.GIT_BRANCH || process.env.BRANCH_NAME,
build: process.env.BUILD_NUMBER,
buildUrl: process.env.BUILD_URL,
root: process.env.WORKSPACE,
pr: process.env.ghprbPullId || process.env.CHANGE_ID,
isPr: Boolean(process.env.ghprbPullId || process.env.CHANGE_ID),
Expand Down
1 change: 1 addition & 0 deletions lib/shippable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
service: 'shippable',
commit: process.env.COMMIT,
build: process.env.BUILD_NUMBER,
buildUrl: process.env.BUILD_URL,
branch: process.env.BASE_BRANCH || process.env.BRANCH,
job: process.env.JOB_NUMBER,
pr: process.env.PULL_REQUEST === 'false' ? undefined : process.env.PULL_REQUEST,
Expand Down
1 change: 1 addition & 0 deletions lib/wercker.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
service: 'wercker',
commit: process.env.WERCKER_GIT_COMMIT,
build: process.env.WERCKER_MAIN_PIPELINE_STARTED,
buildUrl: process.env.WERCKER_RUN_URL,
branch: process.env.WERCKER_GIT_BRANCH,
slug: `${process.env.WERCKER_GIT_OWNER}/${process.env.WERCKER_GIT_REPOSITORY}`,
root: process.env.WERCKER_ROOT,
Expand Down
9 changes: 9 additions & 0 deletions test/appveyor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@ import appveyor from '../lib/appveyor';
test('Push', t => {
process.env.APPVEYOR = 'true';
process.env.APPVEYOR_JOB_NUMBER = '1234';
process.env.APPVEYOR_JOB_ID = 'job_id';
process.env.APPVEYOR_BUILD_VERSION = '100';
process.env.APPVEYOR_REPO_COMMIT = '5678';
process.env.APPVEYOR_BUILD_NUMBER = '91011';
process.env.APPVEYOR_REPO_BRANCH = 'master';
process.env.APPVEYOR_REPO_NAME = 'owner/repo';
process.env.APPVEYOR_PROJECT_SLUG = 'owner/repo';
process.env.APPVEYOR_BUILD_FOLDER = '/';
delete process.env.APPVEYOR_PULL_REQUEST_NUMBER;

t.deepEqual(appveyor.configuration(), {
service: 'appveyor',
commit: '5678',
build: '91011',
buildUrl: 'https://ci.appveyor.com/project/owner/repo/build/100',
branch: 'master',
root: '/',
job: '1234',
jobUrl: 'https://ci.appveyor.com/project/owner/repo/build/job/job_id',
pr: undefined,
isPr: false,
slug: 'owner/repo',
Expand All @@ -27,6 +32,8 @@ test('Push', t => {
test('PR', t => {
process.env.APPVEYOR = 'true';
process.env.APPVEYOR_JOB_NUMBER = '1234';
process.env.APPVEYOR_JOB_ID = 'job_id';
process.env.APPVEYOR_BUILD_VERSION = '100';
process.env.APPVEYOR_REPO_COMMIT = '5678';
process.env.APPVEYOR_BUILD_NUMBER = '91011';
process.env.APPVEYOR_REPO_NAME = 'owner/repo';
Expand All @@ -38,9 +45,11 @@ test('PR', t => {
service: 'appveyor',
commit: '5678',
build: '91011',
buildUrl: 'https://ci.appveyor.com/project/owner/repo/build/100',
branch: 'master',
root: '/',
job: '1234',
jobUrl: 'https://ci.appveyor.com/project/owner/repo/build/job/job_id',
pr: '10',
isPr: true,
slug: 'owner/repo',
Expand Down
18 changes: 10 additions & 8 deletions test/bamboo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ 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_buildKey = '1234';
process.env.bamboo_planRepository_1_revision = '5678';
process.env.bamboo_buildNumber = '91011';
process.env.bamboo_planRepository_1_branchName = 'master';
process.env.bamboo_build_working_directory = '/some/working/dir';
process.env.bamboo_buildResultsUrl = 'https://server.com/buildresult';
/* eslint-enable camelcase */

t.deepEqual(bamboo.configuration(), {
service: 'bamboo',
commit: 'some commit hash',
build: 'some build number',
branch: 'some branch name',
commit: '5678',
build: '91011',
buildUrl: 'https://server.com/buildresult',
branch: 'master',
job: '1234',
root: '/some/working/dir',
job: 'some job number',
});
});
4 changes: 4 additions & 0 deletions test/bitrise.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test('Push', t => {
process.env.BITRISE_IO = 'true';
process.env.BITRISE_GIT_COMMIT = '5678';
process.env.BITRISE_BUILD_NUMBER = '91011';
process.env.BITRISE_BUILD_URL = 'https://server.com/buildresult';
process.env.BITRISE_GIT_BRANCH = 'master';
process.env.BITRISE_PULL_REQUEST = 'false';
process.env.BITRISE_APP_SLUG = 'owner/repo';
Expand All @@ -13,6 +14,7 @@ test('Push', t => {
service: 'bitrise',
commit: '5678',
build: '91011',
buildUrl: 'https://server.com/buildresult',
branch: 'master',
pr: undefined,
isPr: false,
Expand All @@ -24,6 +26,7 @@ test('PR', t => {
process.env.BITRISE_IO = 'true';
process.env.BITRISE_GIT_COMMIT = '5678';
process.env.BITRISE_BUILD_NUMBER = '91011';
process.env.BITRISE_BUILD_URL = 'https://server.com/buildresult';
process.env.BITRISE_GIT_BRANCH = 'master';
process.env.BITRISE_PULL_REQUEST = '10';
process.env.BITRISE_APP_SLUG = 'owner/repo';
Expand All @@ -32,6 +35,7 @@ test('PR', t => {
service: 'bitrise',
commit: '5678',
build: '91011',
buildUrl: 'https://server.com/buildresult',
branch: 'master',
pr: '10',
isPr: true,
Expand Down
3 changes: 3 additions & 0 deletions test/buildkite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ test('Push', t => {
process.env.BUILDKITE = 'true';
process.env.BUILDKITE_COMMIT = '5678';
process.env.BUILDKITE_BUILD_NUMBER = '91011';
process.env.BUILDKITE_BUILD_URL = 'https://server.com/buildresult';
process.env.BUILDKITE_BRANCH = 'master';
process.env.BUILDKITE_PULL_REQUEST = 'false';
process.env.BUILDKITE_BUILD_CHECKOUT_PATH = '/';
Expand All @@ -15,6 +16,7 @@ test('Push', t => {
service: 'buildkite',
commit: '5678',
build: '91011',
buildUrl: 'https://server.com/buildresult',
branch: 'master',
root: '/',
pr: undefined,
Expand All @@ -37,6 +39,7 @@ test('PR', t => {
service: 'buildkite',
commit: '5678',
build: '91011',
buildUrl: 'https://server.com/buildresult',
branch: 'master',
root: '/',
pr: '10',
Expand Down
Loading

0 comments on commit bedc975

Please sign in to comment.