summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo <beschi.jacopo@gmail.com>2018-06-01 15:52:24 +0200
committerJacopo <beschi.jacopo@gmail.com>2018-06-01 17:02:02 +0200
commit3871ea33ca524ef2d420a4ff311d8535622bd150 (patch)
tree199fa276cdc004a5df1ef2bea28ff637c99c5f62
parent6ae16b6d4d9fb79b715875073bb78efd3f56929b (diff)
downloadgitlab-ce-3871ea33ca524ef2d420a4ff311d8535622bd150.tar.gz
Review 1
-rw-r--r--doc/api/pipelines.md2
-rw-r--r--lib/api/pipelines.rb6
-rw-r--r--spec/requests/api/pipelines_spec.rb29
3 files changed, 29 insertions, 8 deletions
diff --git a/doc/api/pipelines.md b/doc/api/pipelines.md
index 0e752056642..ae6c6ea7b49 100644
--- a/doc/api/pipelines.md
+++ b/doc/api/pipelines.md
@@ -102,7 +102,7 @@ POST /projects/:id/pipeline
|------------|---------|----------|---------------------|
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
| `ref` | string | yes | Reference to commit |
-| `variables` | array | no | An array containing the variables available in the pipeline matching the structure [{ 'key' => 'UPLOAD_TO_S3', 'value' => 'true' }] |
+| `variables` | array | no | An array containing the variables available in the pipeline, matching the structure [{ 'key' => 'UPLOAD_TO_S3', 'value' => 'true' }] |
```
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/pipeline?ref=master"
diff --git a/lib/api/pipelines.rb b/lib/api/pipelines.rb
index 378d9585eb8..8374a57edfa 100644
--- a/lib/api/pipelines.rb
+++ b/lib/api/pipelines.rb
@@ -48,9 +48,13 @@ module API
authorize! :create_pipeline, user_project
+ pipeline_params = declared_params(include_missing: false)
+ .merge(variables_attributes: params[:variables])
+ .except(:variables)
+
new_pipeline = Ci::CreatePipelineService.new(user_project,
current_user,
- declared_params(include_missing: false).merge(variables_attributes: params[:variables]))
+ pipeline_params)
.execute(:api, ignore_skip_ci: true, save_on_errors: false)
if new_pipeline.persisted?
diff --git a/spec/requests/api/pipelines_spec.rb b/spec/requests/api/pipelines_spec.rb
index 0c6bb56e11d..0a64c46bb92 100644
--- a/spec/requests/api/pipelines_spec.rb
+++ b/spec/requests/api/pipelines_spec.rb
@@ -316,18 +316,35 @@ describe API::Pipelines do
end
end
- context 'when excluding a ref' do
+ describe 'using variables conditions' do
+ let(:variables) { [{ 'key' => 'STAGING', 'value' => 'true' }] }
+
before do
- config = YAML.dump(test: { script: 'test', except: [project.default_branch] })
+ config = YAML.dump(test: { script: 'test', only: { variables: ['$STAGING'] } })
stub_ci_pipeline_yaml_file(config)
end
- it "doesn't not create a job for the exluded ref" do
+ it 'creates and returns a new pipeline using the given variables' do
expect do
- post api("/projects/#{project.id}/pipeline", user), ref: project.default_branch
- end.not_to change { project.pipelines.count }
+ post api("/projects/#{project.id}/pipeline", user), ref: project.default_branch, variables: variables
+ end.to change { project.pipelines.count }.by(1)
- expect(response).to have_gitlab_http_status(400)
+ expect(response).to have_gitlab_http_status(201)
+ expect(json_response).to be_a Hash
+ expect(json_response['sha']).to eq project.commit.id
+ expect(json_response['variables']).to eq variables
+ end
+
+ context 'condition unmatch' do
+ let(:variables) { [{ 'key' => 'STAGING', 'value' => 'false' }] }
+
+ it "doesn't create a job" do
+ expect do
+ post api("/projects/#{project.id}/pipeline", user), ref: project.default_branch
+ end.not_to change { project.pipelines.count }
+
+ expect(response).to have_gitlab_http_status(400)
+ end
end
end