Skip to content

Commit c10f220

Browse files
committed
feat: add support for tag variable
1 parent 50493bb commit c10f220

24 files changed

+76
-32
lines changed

README.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ $ npm install --save env-ci
1919
```js
2020
const envCi = require('env-ci');
2121

22-
const {isCi, name, service, commit, build, buildUrl, branch, job, jobUrl, pr, isPr, slug, root} = envCi();
22+
const {name, service, isCi, branch, commit, tag, build, buildUrl, job, jobUrl, isPr, pr, slug, root} = envCi();
2323

2424
if (isCI) {
2525
console.log(`Building branch ${branch} of repo ${slug} on ${name}`);
@@ -38,45 +38,46 @@ if (isCI) {
3838

3939
| Variable | Description |
4040
|------------|-----------------------------------------------------------------------------------|
41-
| `isCi` | `true` is running on a CI, `false` otherwise |
4241
| `name` | CI service Commercial name (e.g. `Travis CI`, `CircleCI`, `GitLab CI/CD`) |
4342
| `service` | Standardized CI service name (e.g. `travis`, `circleci`, `gitlab`) |
43+
| `isCi` | `true` is running on a CI, `false` otherwise |
44+
| `branch` | Git branch being built or targeted by a pull request |
4445
| `commit` | Commit sha that triggered the CI build |
46+
| `tag` | Git tag that triggered the CI build |
4547
| `build` | CI service build number |
4648
| `buildUrl` | Link to the CI service build |
47-
| `branch` | Git branch being built or targeted by a pull request |
4849
| `job` | CI service job number |
4950
| `jobUrl` | Link to the CI service job |
50-
| `pr` | Pull Request number |
5151
| `isPr` | `true` is the build has been triggered by a Pull Request, `false` otherwise |
52-
| `slug` | The slug (in form: owner_name/repo_name) of the repository currently being built. |
52+
| `pr` | Pull Request number |
53+
| `slug` | The slug (in form: owner_name/repo_name) of the repository currently being built |
5354
| `root` | The path to the directory where the repository is being built |
5455

5556
**Note**: Some variables can be detected only on certain CI services. See [Supported CI](#supported-ci).
5657

5758
## Supported CI
5859

59-
| CI Service (`name`) | `service` | `isCi` | `commit` | `build` | `buildUrl` | `branch` | `job` | `jobUrl` | `pr` | `isPr` | `slug` | `root` |
60-
|----------------------------------------------------------------------------------------------------------------|:-----------:|:------:|:--------:|:-------:|:----------:|:--------:|:-----:|:--------:|:----:|:------:|:------:|:------:|
61-
| [AppVeyor]( https://www.appveyor.com/docs/environment-variables) | `appveyor` |||| ||||| |||
62-
| [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html) | `bamboo` |||| ||||| |||
63-
| [Bitbucket](https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html) | `bitbucket` |||| ||||| |||
64-
| [Bitrise](http://devcenter.bitrise.io/faq/available-environment-variables/#exposed-by-bitriseio) | `bitrise` |||| ||||| |||
65-
| [Buddy](https://buddy.works/knowledge/deployments/how-use-environment-variables#default-environment-variables) | `buddy` |||| ||||| |||
66-
| [Buildkite](https://buildkite.com/docs/builds/environment-variables) | `buildkite` |||| ||||| |||
67-
| [CircleCI](https://circleci.com/docs/1.0/environment-variables) | `circleci` |||| ||||| |||
68-
| [Cirrus CI](https://cirrus-ci.org/guide/writing-tasks/#environment-variables) | `cirrus` |||| ||||| |||
69-
| [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html) | `codebuild` |||| ||||| |||
70-
| [Codeship](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables) | `codeship` |||| ||||| |||
71-
| [Drone](http://readme.drone.io/0.5/usage/environment-reference) | `drone` |||| | |||| |||
72-
| [Gitlab CI/CD](https://docs.gitlab.com/ce/ci/variables/README.html) | `gitlab` |||| ||||| |||
73-
| [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project) | `jenkins` |||| ||||| |||
74-
| [Semaphore](https://semaphoreci.com/docs/available-environment-variables.html) | `semaphore` |||| | |||| |||
75-
| [Shippable](http://docs.shippable.com/ci/env-vars/#stdEnv) | `shippable` |||| ||||| |||
76-
| [TeamCity](https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters) | `teamcity` |||| | |||| |||
77-
| [Travis CI](https://docs.travis-ci.com/user/environment-variables) | `travis` |||| | |||| |||
78-
| [Visual Studio Team Services](https://docs.microsoft.com/en-us/vsts/pipelines/build/variables) | `vsts` |||| | |||| |||
79-
| [Wercker](http://devcenter.wercker.com/docs/environment-variables/available-env-vars#hs_cos_wrapper_name) | `wercker` |||| ||||| |||
60+
| CI Service (`name`) | `service` | `isCi` | `branch` | `commit` | `tag` | `build` | `buildUrl` | `job` | `jobUrl` | `isPr` | `pr` | `slug` | `root` |
61+
|----------------------------------------------------------------------------------------------------------------------------------------|:-----------:|:------:|:--------:|:--------:|:-----:|:-------:|:----------:|:-----:|:--------:|:------:|:----:|:------:|:------:|
62+
| [AppVeyor]( https://www.appveyor.com/docs/environment-variables) | `appveyor` ||| | | | ||| | |||
63+
| [Bamboo](https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html) | `bamboo` ||| | | | ||| | |||
64+
| [Bitbucket](https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html) | `bitbucket` ||| | | | ||| | |||
65+
| [Bitrise](https://devcenter.bitrise.io/builds/available-environment-variables/#exposed-by-bitriseio) | `bitrise` ||| | | | ||| | |||
66+
| [Buddy](https://buddy.works/knowledge/deployments/how-use-environment-variables#default-environment-variables) | `buddy` ||| | | | ||| | |||
67+
| [Buildkite](https://buildkite.com/docs/builds/environment-variables) | `buildkite` ||| | | | ||| | |||
68+
| [CircleCI](https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables) | `circleci` ||| | | | ||| | |||
69+
| [Cirrus CI](https://cirrus-ci.org/guide/writing-tasks/#environment-variables) | `cirrus` ||| | | | ||| | |||
70+
| [AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-env-vars.html) | `codebuild` ||| | | | ||| | |||
71+
| [Codeship](https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables/#default-environment-variables) | `codeship` ||| | | | ||| | |||
72+
| [Drone](https://readme.drone.io/reference/environ/) | `drone` ||| | | | ||| | |||
73+
| [Gitlab CI/CD](https://docs.gitlab.com/ce/ci/variables/README.html) | `gitlab` ||| | | | ||| | |||
74+
| [Jenkins](https://wiki.jenkins.io/display/JENKINS/Building+a+software+project) | `jenkins` ||| | | | ||| | |||
75+
| [Semaphore](https://semaphoreci.com/docs/available-environment-variables.html) | `semaphore` ||| | | | ||| | |||
76+
| [Shippable](http://docs.shippable.com/ci/env-vars/#stdEnv) | `shippable` ||| | | | ||| | |||
77+
| [TeamCity](https://confluence.jetbrains.com/display/TCD10/Predefined+Build+Parameters) | `teamcity` ||| | | | ||| | |||
78+
| [Travis CI](https://docs.travis-ci.com/user/environment-variables#default-environment-variables) | `travis` ||| | | | ||| | |||
79+
| [Visual Studio Team Services](https://docs.microsoft.com/en-us/vsts/pipelines/build/variables) | `vsts` ||| | | | ||| | |||
80+
| [Wercker](http://devcenter.wercker.com/docs/environment-variables/available-env-vars#hs_cos_wrapper_name) | `wercker` ||| | | | ||| | |||
8081

8182
**Note**: 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.
8283

lib/appveyor.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
name: 'Appveyor',
1010
service: 'appveyor',
1111
commit: env.APPVEYOR_REPO_COMMIT,
12+
tag: env.APPVEYOR_REPO_TAG_NAME,
1213
build: env.APPVEYOR_BUILD_NUMBER,
1314
buildUrl: `https://ci.appveyor.com/project/${env.APPVEYOR_PROJECT_SLUG}/build/${env.APPVEYOR_BUILD_VERSION}`,
1415
branch: env.APPVEYOR_REPO_BRANCH,

lib/bitbucket.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
name: 'Bitbucket Pipelines',
1010
service: 'bitbucket',
1111
commit: env.BITBUCKET_COMMIT,
12+
tag: env.BITBUCKET_TAG,
1213
build: env.BITBUCKET_BUILD_NUMBER,
1314
buildUrl: `https://bitbucket.org/${env.BITBUCKET_REPO_SLUG}/addon/pipelines/home#!/results/${
1415
env.BITBUCKET_BUILD_NUMBER

lib/bitrise.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// http://devcenter.bitrise.io/faq/available-environment-variables
1+
// https://devcenter.bitrise.io/builds/available-environment-variables/#exposed-by-bitriseio
22

33
module.exports = {
44
detect({env}) {
@@ -9,6 +9,7 @@ module.exports = {
99
name: 'Bitrise',
1010
service: 'bitrise',
1111
commit: env.BITRISE_GIT_COMMIT,
12+
tag: env.BITRISE_GIT_TAG,
1213
build: env.BITRISE_BUILD_NUMBER,
1314
buildUrl: env.BITRISE_BUILD_URL,
1415
branch: env.BITRISE_GIT_BRANCH,

lib/buddy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
name: 'Buddy',
1010
service: 'buddy',
1111
commit: env.BUDDY_EXECUTION_REVISION,
12+
tag: env.BUDDY_EXECUTION_TAG,
1213
build: env.BUDDY_EXECUTION_ID,
1314
buildUrl: env.BUDDY_EXECUTION_URL,
1415
branch: env.BUDDY_EXECUTION_BRANCH,

lib/buildkite.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
build: env.BUILDKITE_BUILD_NUMBER,
1212
buildUrl: env.BUILDKITE_BUILD_URL,
1313
commit: env.BUILDKITE_COMMIT,
14+
tag: env.BUILDKITE_TAG,
1415
branch: env.BUILDKITE_BRANCH,
1516
slug: `${env.BUILDKITE_ORGANIZATION_SLUG}/${env.BUILDKITE_PROJECT_SLUG}`,
1617
pr: env.BUILDKITE_PULL_REQUEST === 'false' ? undefined : env.BUILDKITE_PULL_REQUEST,

lib/circleci.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// Circle 1.0 docs: https://circleci.com/docs/1.0/environment-variables
2-
// Circle 2.0 docs: https://circleci.com/docs/2.0/env-vars/
1+
// Circle 2.0 docs: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables
32

43
module.exports = {
54
detect({env}) {
@@ -16,6 +15,7 @@ module.exports = {
1615
buildUrl: env.CIRCLE_BUILD_URL,
1716
job: `${env.CIRCLE_BUILD_NUM}.${env.CIRCLE_NODE_INDEX}`,
1817
commit: env.CIRCLE_SHA1,
18+
tag: env.CIRCLE_TAG,
1919
branch: env.CIRCLE_BRANCH,
2020
pr: pullRequest,
2121
isPr: Boolean(pullRequest),

lib/cirrus.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
name: 'Cirrus CI',
1212
service: 'cirrus',
1313
commit: env.CIRRUS_CHANGE_IN_REPO,
14+
tag: env.CIRRUS_TAG,
1415
build: env.CIRRUS_BUILD_ID,
1516
buildUrl: `${CIRRUS_CI_DASHBOARD}/build/${env.CIRRUS_BUILD_ID}`,
1617
job: env.CIRRUS_TASK_ID,

lib/codeship.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables
1+
// https://documentation.codeship.com/basic/builds-and-configuration/set-environment-variables/#default-environment-variables
22

33
module.exports = {
44
detect({env}) {

lib/drone.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// http://readme.drone.io/0.5/usage/environment-reference
1+
// https://readme.drone.io/reference/environ
22

33
module.exports = {
44
detect({env}) {
@@ -9,6 +9,7 @@ module.exports = {
99
name: 'Drone',
1010
service: 'drone',
1111
commit: env.DRONE_COMMIT_SHA,
12+
tag: env.DRONE_TAG,
1213
build: env.DRONE_BUILD_NUMBER,
1314
branch: env.DRONE_BRANCH,
1415
job: env.DRONE_JOB_NUMBER,

lib/gitlab.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
name: 'GitLab CI/CD',
1010
service: 'gitlab',
1111
commit: env.CI_COMMIT_SHA,
12+
tag: env.CI_COMMIT_TAG,
1213
build: env.CI_PIPELINE_ID,
1314
buildUrl: `${env.CI_PROJECT_URL}/pipelines/${env.CI_PIPELINE_ID}`,
1415
job: env.CI_JOB_ID,

lib/shippable.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
name: 'Shippable',
1010
service: 'shippable',
1111
commit: env.COMMIT,
12+
tag: env.GIT_TAG_NAME,
1213
build: env.BUILD_NUMBER,
1314
buildUrl: env.BUILD_URL,
1415
branch: env.BASE_BRANCH || env.BRANCH,

lib/travis.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// https://docs.travis-ci.com/user/environment-variables
1+
// https://docs.travis-ci.com/user/environment-variables#default-environment-variables
22

33
module.exports = {
44
detect({env}) {
@@ -9,6 +9,7 @@ module.exports = {
99
name: 'Travis CI',
1010
service: 'travis',
1111
commit: env.TRAVIS_COMMIT,
12+
tag: env.TRAVIS_TAG,
1213
build: env.TRAVIS_BUILD_NUMBER,
1314
branch: env.TRAVIS_BRANCH,
1415
job: env.TRAVIS_JOB_NUMBER,

test/appveyor.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const env = {
77
APPVEYOR_JOB_ID: 'job_id',
88
APPVEYOR_BUILD_VERSION: '100',
99
APPVEYOR_REPO_COMMIT: '5678',
10+
APPVEYOR_REPO_TAG_NAME: 'tag_name',
1011
APPVEYOR_BUILD_NUMBER: '91011',
1112
APPVEYOR_REPO_BRANCH: 'master',
1213
APPVEYOR_REPO_NAME: 'owner/repo',
@@ -19,6 +20,7 @@ test('Push', t => {
1920
name: 'Appveyor',
2021
service: 'appveyor',
2122
commit: '5678',
23+
tag: 'tag_name',
2224
build: '91011',
2325
buildUrl: 'https://ci.appveyor.com/project/owner/repo/build/100',
2426
branch: 'master',
@@ -36,6 +38,7 @@ test('PR', t => {
3638
name: 'Appveyor',
3739
service: 'appveyor',
3840
commit: '5678',
41+
tag: 'tag_name',
3942
build: '91011',
4043
buildUrl: 'https://ci.appveyor.com/project/owner/repo/build/100',
4144
branch: 'master',

test/bitbucket.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import bitbucket from '../lib/bitbucket';
33

44
const env = {
55
BITBUCKET_COMMIT: 'b5ce5ce',
6+
BITBUCKET_TAG: 'tag_name',
67
BITBUCKET_BUILD_NUMBER: '1964',
78
BITBUCKET_BRANCH: 'master',
89
BITBUCKET_REPO_SLUG: 'owner/repo',
@@ -14,6 +15,7 @@ test('Push', t => {
1415
name: 'Bitbucket Pipelines',
1516
service: 'bitbucket',
1617
commit: 'b5ce5ce',
18+
tag: 'tag_name',
1719
build: '1964',
1820
buildUrl: 'https://bitbucket.org/owner/repo/addon/pipelines/home#!/results/1964',
1921
branch: 'master',

test/bitrise.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import bitrise from '../lib/bitrise';
44
const env = {
55
BITRISE_IO: 'true',
66
BITRISE_GIT_COMMIT: '5678',
7+
BITRISE_GIT_TAG: 'tag_name',
78
BITRISE_BUILD_NUMBER: '91011',
89
BITRISE_BUILD_URL: 'https://server.com/buildresult',
910
BITRISE_GIT_BRANCH: 'master',
@@ -16,6 +17,7 @@ test('Push', t => {
1617
name: 'Bitrise',
1718
service: 'bitrise',
1819
commit: '5678',
20+
tag: 'tag_name',
1921
build: '91011',
2022
buildUrl: 'https://server.com/buildresult',
2123
branch: 'master',
@@ -30,6 +32,7 @@ test('PR', t => {
3032
name: 'Bitrise',
3133
service: 'bitrise',
3234
commit: '5678',
35+
tag: 'tag_name',
3336
build: '91011',
3437
buildUrl: 'https://server.com/buildresult',
3538
branch: 'master',

0 commit comments

Comments
 (0)