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
c99522f2
Commit
c99522f2
authored
Nov 21, 2016
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'create-pipeline-endpoint' into 'master'
Add API endpoint for creating a pipeline Fixes #23468 See merge request !7209
parents
b98193c5
fbfc7523
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
0 deletions
+117
-0
create-pipeline-endpoint.yml
changelogs/unreleased/create-pipeline-endpoint.yml
+4
-0
pipelines.md
doc/api/pipelines.md
+46
-0
pipelines.rb
lib/api/pipelines.rb
+21
-0
pipelines_spec.rb
spec/requests/api/pipelines_spec.rb
+46
-0
No files found.
changelogs/unreleased/create-pipeline-endpoint.yml
0 → 100644
View file @
c99522f2
---
title
:
Add api endpoint for creating a pipeline
merge_request
:
7209
author
:
Ido Leibovich
doc/api/pipelines.md
View file @
c99522f2
...
...
@@ -114,6 +114,51 @@ Example of response
}
```
## Create a new pipeline
> [Introduced][ce-7209] in GitLab 8.14
```
POST /projects/:id/pipeline
```
| Attribute | Type | Required | Description |
|------------|---------|----------|---------------------|
|
`id`
| integer | yes | The ID of a project |
|
`ref`
| string | yes | Reference to commit |
```
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/pipeline?ref=master"
```
Example of response
```
json
{
"id"
:
61
,
"sha"
:
"384c444e840a515b23f21915ee5766b87068a70d"
,
"ref"
:
"master"
,
"status"
:
"pending"
,
"before_sha"
:
"0000000000000000000000000000000000000000"
,
"tag"
:
false
,
"yaml_errors"
:
null
,
"user"
:
{
"name"
:
"Administrator"
,
"username"
:
"root"
,
"id"
:
1
,
"state"
:
"active"
,
"avatar_url"
:
"http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon"
,
"web_url"
:
"http://localhost:3000/root"
},
"created_at"
:
"2016-11-04T09:36:13.747Z"
,
"updated_at"
:
"2016-11-04T09:36:13.977Z"
,
"started_at"
:
null
,
"finished_at"
:
null
,
"committed_at"
:
null
,
"duration"
:
null
}
```
## Retry failed builds in a pipeline
> [Introduced][ce-5837] in GitLab 8.11
...
...
@@ -205,3 +250,4 @@ Response:
```
[
ce-5837
]:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/5837
[
ce-7209
]:
https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/7209
lib/api/pipelines.rb
View file @
c99522f2
...
...
@@ -22,6 +22,27 @@ module API
pipelines
=
PipelinesFinder
.
new
(
user_project
).
execute
(
scope:
params
[
:scope
])
present
paginate
(
pipelines
),
with:
Entities
::
Pipeline
end
desc
'Create a new pipeline'
do
detail
'This feature was introduced in GitLab 8.14'
success
Entities
::
Pipeline
end
params
do
requires
:ref
,
type:
String
,
desc:
'Reference'
end
post
':id/pipeline'
do
authorize!
:create_pipeline
,
user_project
new_pipeline
=
Ci
::
CreatePipelineService
.
new
(
user_project
,
current_user
,
declared_params
(
include_missing:
false
))
.
execute
(
ignore_skip_ci:
true
,
save_on_errors:
false
)
if
new_pipeline
.
persisted?
present
new_pipeline
,
with:
Entities
::
Pipeline
else
render_validation_error!
(
new_pipeline
)
end
end
desc
'Gets a specific pipeline for the project'
do
detail
'This feature was introduced in GitLab 8.11'
...
...
spec/requests/api/pipelines_spec.rb
View file @
c99522f2
...
...
@@ -41,6 +41,52 @@ describe API::API, api: true do
end
end
describe
'POST /projects/:id/pipeline '
do
context
'authorized user'
do
context
'with gitlab-ci.yml'
do
before
{
stub_ci_pipeline_to_return_yaml_file
}
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
)
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
).
to
be_a
Hash
expect
(
json_response
[
'sha'
]).
to
eq
project
.
commit
.
id
end
it
'fails when using an invalid ref'
do
post
api
(
"/projects/
#{
project
.
id
}
/pipeline"
,
user
),
ref:
'invalid_ref'
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'base'
].
first
).
to
eq
'Reference not found'
expect
(
json_response
).
not_to
be_an
Array
end
end
context
'without gitlab-ci.yml'
do
it
'fails to create pipeline'
do
post
api
(
"/projects/
#{
project
.
id
}
/pipeline"
,
user
),
ref:
project
.
default_branch
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
][
'base'
].
first
).
to
eq
'Missing .gitlab-ci.yml file'
expect
(
json_response
).
not_to
be_an
Array
end
end
end
context
'unauthorized user'
do
it
'does not create pipeline'
do
post
api
(
"/projects/
#{
project
.
id
}
/pipeline"
,
non_member
),
ref:
project
.
default_branch
expect
(
response
).
to
have_http_status
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
'404 Project Not Found'
expect
(
json_response
).
not_to
be_an
Array
end
end
end
describe
'GET /projects/:id/pipelines/:pipeline_id'
do
context
'authorized user'
do
it
'returns project pipelines'
do
...
...
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