diff options
author | Kamil Trzciński <ayufan@ayufan.eu> | 2015-08-05 15:11:47 +0000 |
---|---|---|
committer | Kamil Trzciński <ayufan@ayufan.eu> | 2015-08-05 15:11:47 +0000 |
commit | c790a1d4a19c5b78fb4fe47f1466c842006456c0 (patch) | |
tree | 81fb41ab59f5581ce7341f4bb42cb78dbdacb119 /spec | |
parent | 3ee72501882a48b89f14a58f0c6093d35c7bf9cd (diff) | |
parent | faee0750d08787993727f10a008c70aa63f8814c (diff) | |
download | gitlab-ci-c790a1d4a19c5b78fb4fe47f1466c842006456c0.tar.gz |
Merge branch 'yaml-variables' into 'master'
Support yaml variables
This MR introduces ability to define variables from YAML.
```yaml
variables:
DB_NAME: postgres
test:
script: echo $DB_NAME
```
The variables are passed using the same API as Secure Variables. The API introduces additional parameter: public. All variables defined in YAML are marked as public. The GitLab Runner when detects public variables will pass them to the services. This makes it easy to fine tune linked services to for example define database name.
```yaml
services:
- postgres
variables:
POSTGRES_DB: gitlab
```
The above example will run [postgres](https://registry.hub.docker.com/u/library/postgres/) and pass POSTGRES_DB to postgres container making it to create `gitlab` database instead of default `postges`.
**Note:** All variables will passed to all service containers. It's not designed to distinguish which variable should go where.
/cc @sytses @vsizov @dzaporozhets
See merge request !227
Diffstat (limited to 'spec')
-rw-r--r-- | spec/lib/gitlab_ci_yaml_processor_spec.rb | 33 | ||||
-rw-r--r-- | spec/requests/api/builds_spec.rb | 5 | ||||
-rw-r--r-- | spec/support/gitlab_stubs/gitlab_ci.yml | 3 |
3 files changed, 39 insertions, 2 deletions
diff --git a/spec/lib/gitlab_ci_yaml_processor_spec.rb b/spec/lib/gitlab_ci_yaml_processor_spec.rb index fdd77ed..5b9a4f1 100644 --- a/spec/lib/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/gitlab_ci_yaml_processor_spec.rb @@ -153,6 +153,23 @@ describe GitlabCiYamlProcessor do end end + describe "Variables" do + it "returns variables when defined" do + variables = { + var1: "value1", + var2: "value2", + } + config = YAML.dump({ + variables: variables, + before_script: ["pwd"], + rspec: {script: "rspec"} + }) + + config_processor = GitlabCiYamlProcessor.new(config) + config_processor.variables.should == variables + end + end + describe "Error handling" do it "indicates that object is invalid" do expect{GitlabCiYamlProcessor.new("invalid_yaml\n!ccdvlf%612334@@@@")}.to raise_error(GitlabCiYamlProcessor::ValidationError) @@ -269,5 +286,19 @@ describe GitlabCiYamlProcessor do GitlabCiYamlProcessor.new(config) end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings") end + + it "returns errors if variables is not a map" do + config = YAML.dump({variables: "test", rspec: {script: "test"}}) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings") + end + + it "returns errors if variables is not a map of key-valued strings" do + config = YAML.dump({variables: {test: false}, rspec: {script: "test"}}) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings") + end end -end
\ No newline at end of file +end diff --git a/spec/requests/api/builds_spec.rb b/spec/requests/api/builds_spec.rb index b44798b..a169f8e 100644 --- a/spec/requests/api/builds_spec.rb +++ b/spec/requests/api/builds_spec.rb @@ -69,7 +69,10 @@ describe API::API do post api("/builds/register"), token: runner.token, info: {platform: :darwin} response.status.should == 201 - json_response["variables"].should == [{"key" => "SECRET_KEY", "value" => "secret_value"}] + json_response["variables"].should == [ + {"key" => "DB_NAME", "value" => "postgres", "public" => true}, + {"key" => "SECRET_KEY", "value" => "secret_value", "public" => false}, + ] end end diff --git a/spec/support/gitlab_stubs/gitlab_ci.yml b/spec/support/gitlab_stubs/gitlab_ci.yml index 8533cdb..3482145 100644 --- a/spec/support/gitlab_stubs/gitlab_ci.yml +++ b/spec/support/gitlab_stubs/gitlab_ci.yml @@ -7,6 +7,9 @@ before_script: - bundle install - bundle exec rake db:create +variables: + DB_NAME: postgres + types: - test - deploy |