summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacopo <beschi.jacopo@gmail.com>2018-05-24 08:55:47 +0200
committerJacopo <beschi.jacopo@gmail.com>2018-06-01 14:23:45 +0200
commit9b2e19fe37a5d1389e9f83531bb6ba4b06a66de0 (patch)
tree8a56fa1ff3b4aa11801a0eda679388ab1ee94fa9
parent709e8b263863c5a92959700b67462c2ebe4f1831 (diff)
downloadgitlab-ce-9b2e19fe37a5d1389e9f83531bb6ba4b06a66de0.tar.gz
Adds variables to POST api/v4/projects/:id/pipeline
-rw-r--r--changelogs/unreleased/25045-add-variables-to-post-pipeline-api.yml5
-rw-r--r--doc/api/pipelines.md4
-rw-r--r--lib/api/entities.rb1
-rw-r--r--lib/api/pipelines.rb1
-rw-r--r--spec/requests/api/pipelines_spec.rb17
5 files changed, 26 insertions, 2 deletions
diff --git a/changelogs/unreleased/25045-add-variables-to-post-pipeline-api.yml b/changelogs/unreleased/25045-add-variables-to-post-pipeline-api.yml
new file mode 100644
index 00000000000..1e648b75248
--- /dev/null
+++ b/changelogs/unreleased/25045-add-variables-to-post-pipeline-api.yml
@@ -0,0 +1,5 @@
+---
+title: Add variables to POST api/v4/projects/:id/pipeline
+merge_request: 19124
+author: Jacopo Beschi @jacopo-beschi
+type: added
diff --git a/doc/api/pipelines.md b/doc/api/pipelines.md
index 899f5da6647..bc96b3a0bdf 100644
--- a/doc/api/pipelines.md
+++ b/doc/api/pipelines.md
@@ -102,6 +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_attributes` | 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"
@@ -132,7 +133,8 @@ Example of response
"finished_at": null,
"committed_at": null,
"duration": null,
- "coverage": null
+ "coverage": null,
+ "variables": []
}
```
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index c4537036a3a..8773e2c029a 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -1067,6 +1067,7 @@ module API
expose :created_at, :updated_at, :started_at, :finished_at, :committed_at
expose :duration
expose :coverage
+ expose :variables, using: Entities::Variable
end
class PipelineSchedule < Grape::Entity
diff --git a/lib/api/pipelines.rb b/lib/api/pipelines.rb
index 735591fedd5..85e073ce662 100644
--- a/lib/api/pipelines.rb
+++ b/lib/api/pipelines.rb
@@ -41,6 +41,7 @@ module API
end
params do
requires :ref, type: String, desc: 'Reference'
+ optional :variables_attributes, Array, desc: 'Array of variables available in the pipeline'
end
post ':id/pipeline' do
Gitlab::QueryLimiting.whitelist('https://gitlab.com/gitlab-org/gitlab-ce/issues/42124')
diff --git a/spec/requests/api/pipelines_spec.rb b/spec/requests/api/pipelines_spec.rb
index 0736329f9fd..f20c2275152 100644
--- a/spec/requests/api/pipelines_spec.rb
+++ b/spec/requests/api/pipelines_spec.rb
@@ -294,13 +294,28 @@ describe API::Pipelines do
it 'creates and returns a new pipeline' do
expect do
post api("/projects/#{project.id}/pipeline", user), ref: project.default_branch
- end.to change { Ci::Pipeline.count }.by(1)
+ end.to change { project.pipelines.count }.by(1)
expect(response).to have_gitlab_http_status(201)
expect(json_response).to be_a Hash
expect(json_response['sha']).to eq project.commit.id
end
+ context 'variables given' do
+ let(:variables_attributes) { [{ 'key' => 'UPLOAD_TO_S3', 'value' => 'true' }] }
+
+ 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, variables_attributes: variables_attributes
+ end.to change { project.pipelines.count }.by(1)
+
+ 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_attributes
+ end
+ end
+
it 'fails when using an invalid ref' do
post api("/projects/#{project.id}/pipeline", user), ref: 'invalid_ref'