BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
7b5ab3de
Commit
7b5ab3de
authored
Oct 12, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added CI_BUILD_TAG, _STAGE, _NAME and _TRIGGERED to CI builds
parent
2d0fcb4d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
70 additions
and
19 deletions
+70
-19
CHANGELOG
CHANGELOG
+1
-0
build.rb
app/models/ci/build.rb
+10
-1
README.md
doc/ci/variables/README.md
+24
-14
build_spec.rb
spec/models/build_spec.rb
+30
-4
builds_spec.rb
spec/requests/ci/api/builds_spec.rb
+5
-0
No files found.
CHANGELOG
View file @
7b5ab3de
...
...
@@ -18,6 +18,7 @@ v 8.1.0 (unreleased)
- Add first and last to pagination (Zeger-Jan van de Weg)
- Added Commit Status API
- Show CI status on commit page
- Added CI_BUILD_TAG, _STAGE, _NAME and _TRIGGERED to CI builds
- Show CI status on Your projects page and Starred projects page
- Remove "Continuous Integration" page from dashboard
- Add notes and SSL verification entries to hook APIs (Ben Boeckel)
...
...
app/models/ci/build.rb
View file @
7b5ab3de
...
...
@@ -119,7 +119,7 @@ module Ci
end
def
variables
yaml_variables
+
project_variables
+
trigger_variables
predefined_variables
+
yaml_variables
+
project_variables
+
trigger_variables
end
def
project
...
...
@@ -258,5 +258,14 @@ module Ci
[]
end
end
def
predefined_variables
variables
=
[]
variables
<<
{
key: :CI_BUILD_TAG
,
value:
ref
,
public:
true
}
if
tag
variables
<<
{
key: :CI_BUILD_NAME
,
value:
name
,
public:
true
}
variables
<<
{
key: :CI_BUILD_STAGE
,
value:
stage
,
public:
true
}
variables
<<
{
key: :CI_BUILD_TRIGGERED
,
value:
'true'
,
public:
true
}
if
trigger_request
variables
end
end
end
doc/ci/variables/README.md
View file @
7b5ab3de
...
...
@@ -15,21 +15,27 @@ The API_TOKEN will take the Secure Variable value: `SECURE`.
### Predefined variables (Environment Variables)
| Variable | Description |
| Variable |
Runner |
Description |
|-------------------------|-------------|
|
**CI**
| Mark that build is executed in CI environment |
|
**GITLAB_CI**
| Mark that build is executed in GitLab CI environment |
|
**CI_SERVER**
| Mark that build is executed in CI environment |
|
**CI_SERVER_NAME**
| CI server that is used to coordinate builds |
|
**CI_SERVER_VERSION**
| Not yet defined |
|
**CI_SERVER_REVISION**
| Not yet defined |
|
**CI_BUILD_REF**
| The commit revision for which project is built |
|
**CI_BUILD_BEFORE_SHA**
| The first commit that were included in push request |
|
**CI_BUILD_REF_NAME**
| The branch or tag name for which project is built |
|
**CI_BUILD_ID**
| The unique id of the current build that GitLab CI uses internally |
|
**CI_BUILD_REPO**
| The URL to clone the Git repository |
|
**CI_PROJECT_ID**
| The unique id of the current project that GitLab CI uses internally |
|
**CI_PROJECT_DIR**
| The full path where the repository is cloned and where the build is ran |
|
**CI**
| 0.4 | Mark that build is executed in CI environment |
|
**GITLAB_CI**
| all | Mark that build is executed in GitLab CI environment |
|
**CI_SERVER**
| all | Mark that build is executed in CI environment |
|
**CI_SERVER_NAME**
| all | CI server that is used to coordinate builds |
|
**CI_SERVER_VERSION**
| all | Not yet defined |
|
**CI_SERVER_REVISION**
| all | Not yet defined |
|
**CI_BUILD_REF**
| all | The commit revision for which project is built |
|
**CI_BUILD_TAG**
| 0.5 | The commit tag name. Present only when building tags. |
|
**CI_BUILD_NAME**
| 0.5 | The name of the build as defined in
`.gitlab-ci.yml`
|
|
**CI_BUILD_STAGE**
| 0.5 | The name of the stage as defined in
`.gitlab-ci.yml`
|
|
**CI_BUILD_BEFORE_SHA**
| all | The first commit that were included in push request |
|
**CI_BUILD_REF_NAME**
| all | The branch or tag name for which project is built |
|
**CI_BUILD_ID**
| all | The unique id of the current build that GitLab CI uses internally |
|
**CI_BUILD_REPO**
| all | The URL to clone the Git repository |
|
**CI_BUILD_TRIGGERED**
| 0.5 | The flag to indicate that build was triggered |
|
**CI_PROJECT_ID**
| all | The unique id of the current project that GitLab CI uses internally |
|
**CI_PROJECT_DIR**
| all | The full path where the repository is cloned and where the build is ran |
**Some of the variables are only available when using runner with at least defined version.**
Example values:
...
...
@@ -39,6 +45,10 @@ export CI_BUILD_ID="50"
export
CI_BUILD_REF
=
"1ecfd275763eff1d6b4844ea3168962458c9f27a"
export
CI_BUILD_REF_NAME
=
"master"
export
CI_BUILD_REPO
=
"https://gitlab.com/gitlab-org/gitlab-ce.git"
export
CI_BUILD_TAG
=
"1.0.0"
export
CI_BUILD_NAME
=
"spec:other"
export
CI_BUILD_STAGE
=
"test"
export
CI_BUILD_TRIGGERED
=
"true"
export
CI_PROJECT_DIR
=
"/builds/gitlab-org/gitlab-ce"
export
CI_PROJECT_ID
=
"34"
export
CI_SERVER
=
"yes"
...
...
spec/models/build_spec.rb
View file @
7b5ab3de
...
...
@@ -200,13 +200,34 @@ describe Ci::Build do
context
'returns variables'
do
subject
{
build
.
variables
}
let
(
:variables
)
do
let
(
:predefined_variables
)
do
[
{
key: :CI_BUILD_NAME
,
value:
'test'
,
public:
true
},
{
key: :CI_BUILD_STAGE
,
value:
'stage'
,
public:
true
},
]
end
let
(
:yaml_variables
)
do
[
{
key: :DB_NAME
,
value:
'postgres'
,
public:
true
}
]
end
it
{
is_expected
.
to
eq
(
variables
)
}
before
{
build
.
update_attributes
(
stage:
'stage'
)
}
it
{
is_expected
.
to
eq
(
predefined_variables
+
yaml_variables
)
}
context
'for tag'
do
let
(
:tag_variable
)
do
[
{
key: :CI_BUILD_TAG
,
value:
'master'
,
public:
true
}
]
end
before
{
build
.
update_attributes
(
tag:
true
)
}
it
{
is_expected
.
to
eq
(
tag_variable
+
predefined_variables
+
yaml_variables
)
}
end
context
'and secure variables'
do
let
(
:secure_variables
)
do
...
...
@@ -219,7 +240,7 @@ describe Ci::Build do
build
.
project
.
variables
<<
Ci
::
Variable
.
new
(
key:
'SECRET_KEY'
,
value:
'secret_value'
)
end
it
{
is_expected
.
to
eq
(
variables
+
secure_variables
)
}
it
{
is_expected
.
to
eq
(
predefined_variables
+
yaml_
variables
+
secure_variables
)
}
context
'and trigger variables'
do
let
(
:trigger
)
{
FactoryGirl
.
create
:ci_trigger
,
project:
project
}
...
...
@@ -229,12 +250,17 @@ describe Ci::Build do
{
key: :TRIGGER_KEY
,
value:
'TRIGGER_VALUE'
,
public:
false
}
]
end
let
(
:predefined_trigger_variable
)
do
[
{
key: :CI_BUILD_TRIGGERED
,
value:
'true'
,
public:
true
}
]
end
before
do
build
.
trigger_request
=
trigger_request
end
it
{
is_expected
.
to
eq
(
variables
+
secure_variables
+
trigger_variables
)
}
it
{
is_expected
.
to
eq
(
predefined_variables
+
predefined_trigger_variable
+
yaml_
variables
+
secure_variables
+
trigger_variables
)
}
end
end
end
...
...
spec/requests/ci/api/builds_spec.rb
View file @
7b5ab3de
...
...
@@ -76,6 +76,8 @@ describe Ci::API::API do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
"variables"
]).
to
eq
([
{
"key"
=>
"CI_BUILD_NAME"
,
"value"
=>
"spinach"
,
"public"
=>
true
},
{
"key"
=>
"CI_BUILD_STAGE"
,
"value"
=>
"test"
,
"public"
=>
true
},
{
"key"
=>
"DB_NAME"
,
"value"
=>
"postgres"
,
"public"
=>
true
},
{
"key"
=>
"SECRET_KEY"
,
"value"
=>
"secret_value"
,
"public"
=>
false
},
])
...
...
@@ -93,6 +95,9 @@ describe Ci::API::API do
expect
(
response
.
status
).
to
eq
(
201
)
expect
(
json_response
[
"variables"
]).
to
eq
([
{
"key"
=>
"CI_BUILD_NAME"
,
"value"
=>
"spinach"
,
"public"
=>
true
},
{
"key"
=>
"CI_BUILD_STAGE"
,
"value"
=>
"test"
,
"public"
=>
true
},
{
"key"
=>
"CI_BUILD_TRIGGERED"
,
"value"
=>
"true"
,
"public"
=>
true
},
{
"key"
=>
"DB_NAME"
,
"value"
=>
"postgres"
,
"public"
=>
true
},
{
"key"
=>
"SECRET_KEY"
,
"value"
=>
"secret_value"
,
"public"
=>
false
},
{
"key"
=>
"TRIGGER_KEY"
,
"value"
=>
"TRIGGER_VALUE"
,
"public"
=>
false
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment