Added CI_BUILD_TAG, _STAGE, _NAME and _TRIGGERED to CI builds

This commit is contained in:
Kamil Trzcinski 2015-10-12 17:06:53 +02:00
parent 2d0fcb4de2
commit 7b5ab3ded5
5 changed files with 70 additions and 19 deletions

View file

@ -18,6 +18,7 @@ v 8.1.0 (unreleased)
- Add first and last to pagination (Zeger-Jan van de Weg) - Add first and last to pagination (Zeger-Jan van de Weg)
- Added Commit Status API - Added Commit Status API
- Show CI status on commit page - 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 - Show CI status on Your projects page and Starred projects page
- Remove "Continuous Integration" page from dashboard - Remove "Continuous Integration" page from dashboard
- Add notes and SSL verification entries to hook APIs (Ben Boeckel) - Add notes and SSL verification entries to hook APIs (Ben Boeckel)

View file

@ -119,7 +119,7 @@ module Ci
end end
def variables def variables
yaml_variables + project_variables + trigger_variables predefined_variables + yaml_variables + project_variables + trigger_variables
end end
def project def project
@ -258,5 +258,14 @@ module Ci
[] []
end end
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
end end

View file

@ -15,21 +15,27 @@ The API_TOKEN will take the Secure Variable value: `SECURE`.
### Predefined variables (Environment Variables) ### Predefined variables (Environment Variables)
| Variable | Description | | Variable | Runner | Description |
|-------------------------|-------------| |-------------------------|-------------|
| **CI** | Mark that build is executed in CI environment | | **CI** | 0.4 | Mark that build is executed in CI environment |
| **GITLAB_CI** | Mark that build is executed in GitLab CI environment | | **GITLAB_CI** | all | Mark that build is executed in GitLab CI environment |
| **CI_SERVER** | Mark that build is executed in CI environment | | **CI_SERVER** | all | Mark that build is executed in CI environment |
| **CI_SERVER_NAME** | CI server that is used to coordinate builds | | **CI_SERVER_NAME** | all | CI server that is used to coordinate builds |
| **CI_SERVER_VERSION** | Not yet defined | | **CI_SERVER_VERSION** | all | Not yet defined |
| **CI_SERVER_REVISION** | Not yet defined | | **CI_SERVER_REVISION** | all | Not yet defined |
| **CI_BUILD_REF** | The commit revision for which project is built | | **CI_BUILD_REF** | all | The commit revision for which project is built |
| **CI_BUILD_BEFORE_SHA** | The first commit that were included in push request | | **CI_BUILD_TAG** | 0.5 | The commit tag name. Present only when building tags. |
| **CI_BUILD_REF_NAME** | The branch or tag name for which project is built | | **CI_BUILD_NAME** | 0.5 | The name of the build as defined in `.gitlab-ci.yml` |
| **CI_BUILD_ID** | The unique id of the current build that GitLab CI uses internally | | **CI_BUILD_STAGE** | 0.5 | The name of the stage as defined in `.gitlab-ci.yml` |
| **CI_BUILD_REPO** | The URL to clone the Git repository | | **CI_BUILD_BEFORE_SHA** | all | The first commit that were included in push request |
| **CI_PROJECT_ID** | The unique id of the current project that GitLab CI uses internally | | **CI_BUILD_REF_NAME** | all | The branch or tag name for which project is built |
| **CI_PROJECT_DIR** | The full path where the repository is cloned and where the build is ran | | **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: Example values:
@ -39,6 +45,10 @@ export CI_BUILD_ID="50"
export CI_BUILD_REF="1ecfd275763eff1d6b4844ea3168962458c9f27a" export CI_BUILD_REF="1ecfd275763eff1d6b4844ea3168962458c9f27a"
export CI_BUILD_REF_NAME="master" export CI_BUILD_REF_NAME="master"
export CI_BUILD_REPO="https://gitlab.com/gitlab-org/gitlab-ce.git" 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_DIR="/builds/gitlab-org/gitlab-ce"
export CI_PROJECT_ID="34" export CI_PROJECT_ID="34"
export CI_SERVER="yes" export CI_SERVER="yes"

View file

@ -200,13 +200,34 @@ describe Ci::Build do
context 'returns variables' do context 'returns variables' do
subject { build.variables } 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 } { key: :DB_NAME, value: 'postgres', public: true }
] ]
end 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 context 'and secure variables' do
let(: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') build.project.variables << Ci::Variable.new(key: 'SECRET_KEY', value: 'secret_value')
end 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 context 'and trigger variables' do
let(:trigger) { FactoryGirl.create :ci_trigger, project: project } let(:trigger) { FactoryGirl.create :ci_trigger, project: project }
@ -229,12 +250,17 @@ describe Ci::Build do
{ key: :TRIGGER_KEY, value: 'TRIGGER_VALUE', public: false } { key: :TRIGGER_KEY, value: 'TRIGGER_VALUE', public: false }
] ]
end end
let(:predefined_trigger_variable) do
[
{ key: :CI_BUILD_TRIGGERED, value: 'true', public: true }
]
end
before do before do
build.trigger_request = trigger_request build.trigger_request = trigger_request
end 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 end
end end

View file

@ -76,6 +76,8 @@ describe Ci::API::API do
expect(response.status).to eq(201) expect(response.status).to eq(201)
expect(json_response["variables"]).to eq([ 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" => "DB_NAME", "value" => "postgres", "public" => true },
{ "key" => "SECRET_KEY", "value" => "secret_value", "public" => false }, { "key" => "SECRET_KEY", "value" => "secret_value", "public" => false },
]) ])
@ -93,6 +95,9 @@ describe Ci::API::API do
expect(response.status).to eq(201) expect(response.status).to eq(201)
expect(json_response["variables"]).to eq([ 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" => "DB_NAME", "value" => "postgres", "public" => true },
{ "key" => "SECRET_KEY", "value" => "secret_value", "public" => false }, { "key" => "SECRET_KEY", "value" => "secret_value", "public" => false },
{ "key" => "TRIGGER_KEY", "value" => "TRIGGER_VALUE", "public" => false }, { "key" => "TRIGGER_KEY", "value" => "TRIGGER_VALUE", "public" => false },