Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
140b51ce
Commit
140b51ce
authored
Mar 05, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce tests for pipeline triggers
parent
ab972295
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
145 additions
and
52 deletions
+145
-52
app/helpers/triggers_helper.rb
app/helpers/triggers_helper.rb
+2
-2
changelogs/unreleased/introduce-pipeline-triggers.yml
changelogs/unreleased/introduce-pipeline-triggers.yml
+4
-0
doc/ci/triggers/README.md
doc/ci/triggers/README.md
+8
-8
lib/api/entities.rb
lib/api/entities.rb
+3
-1
lib/api/triggers.rb
lib/api/triggers.rb
+13
-9
spec/requests/api/triggers_spec.rb
spec/requests/api/triggers_spec.rb
+115
-32
No files found.
app/helpers/triggers_helper.rb
View file @
140b51ce
module
TriggersHelper
def
builds_trigger_url
(
project_id
,
ref:
nil
)
if
ref
.
nil?
"
#{
Settings
.
gitlab
.
url
}
/api/v
3/projects/
#{
project_id
}
/trigger/builds
"
"
#{
Settings
.
gitlab
.
url
}
/api/v
4/projects/
#{
project_id
}
/trigger/pipeline
"
else
"
#{
Settings
.
gitlab
.
url
}
/api/v
3/projects/
#{
project_id
}
/ref/
#{
ref
}
/trigger/builds
"
"
#{
Settings
.
gitlab
.
url
}
/api/v
4/projects/
#{
project_id
}
/ref/
#{
ref
}
/trigger/pipeline
"
end
end
...
...
changelogs/unreleased/introduce-pipeline-triggers.yml
0 → 100644
View file @
140b51ce
---
title
:
Introduce Pipeline Triggers that are user-aware
merge_request
:
author
:
doc/ci/triggers/README.md
View file @
140b51ce
...
...
@@ -36,7 +36,7 @@ it will not trigger a job.
To trigger a job you need to send a
`POST`
request to GitLab's API endpoint:
```
POST /projects/:id/trigger/
builds
POST /projects/:id/trigger/
pipeline
```
The required parameters are the trigger's
`token`
and the Git
`ref`
on which
...
...
@@ -71,7 +71,7 @@ To trigger a job from webhook of another project you need to add the following
webhook url for Push and Tag push events:
```
https://gitlab.example.com/api/v4/projects/:id/ref/:ref/trigger/
builds
?token=TOKEN
https://gitlab.example.com/api/v4/projects/:id/ref/:ref/trigger/
pipeline
?token=TOKEN
```
> **Note**:
...
...
@@ -105,7 +105,7 @@ Using cURL you can trigger a rebuild with minimal effort, for example:
curl
--request
POST
\
--form
token
=
TOKEN
\
--form
ref
=
master
\
https://gitlab.example.com/api/v4/projects/9/trigger/
builds
https://gitlab.example.com/api/v4/projects/9/trigger/
pipeline
```
In this case, the project with ID
`9`
will get rebuilt on
`master`
branch.
...
...
@@ -114,7 +114,7 @@ Alternatively, you can pass the `token` and `ref` arguments in the query string:
```
bash
curl
--request
POST
\
"https://gitlab.example.com/api/v4/projects/9/trigger/
builds
?token=TOKEN&ref=master"
"https://gitlab.example.com/api/v4/projects/9/trigger/
pipeline
?token=TOKEN&ref=master"
```
### Triggering a job within `.gitlab-ci.yml`
...
...
@@ -128,7 +128,7 @@ need to add in project's A `.gitlab-ci.yml`:
build_docs
:
stage
:
deploy
script
:
-
"
curl
--request
POST
--form
token=TOKEN
--form
ref=master
https://gitlab.example.com/api/v4/projects/9/trigger/
builds
"
-
"
curl
--request
POST
--form
token=TOKEN
--form
ref=master
https://gitlab.example.com/api/v4/projects/9/trigger/
pipeline
"
only
:
-
tags
```
...
...
@@ -187,7 +187,7 @@ curl --request POST \
--form
token
=
TOKEN
\
--form
ref
=
master
\
--form
"variables[UPLOAD_TO_S3]=true"
\
https://gitlab.example.com/api/v4/projects/9/trigger/
builds
https://gitlab.example.com/api/v4/projects/9/trigger/
pipeline
```
### Using webhook to trigger job
...
...
@@ -195,7 +195,7 @@ curl --request POST \
You can add the following webhook to another project in order to trigger a job:
```
https://gitlab.example.com/api/v4/projects/9/ref/master/trigger/
builds
?token=TOKEN&variables[UPLOAD_TO_S3]=true
https://gitlab.example.com/api/v4/projects/9/ref/master/trigger/
pipeline
?token=TOKEN&variables[UPLOAD_TO_S3]=true
```
### Using cron to trigger nightly jobs
...
...
@@ -205,7 +205,7 @@ in conjunction with cron. The example below triggers a job on the `master`
branch of project with ID
`9`
every night at
`00:30`
:
```
bash
30 0
*
*
*
curl
--request
POST
--form
token
=
TOKEN
--form
ref
=
master https://gitlab.example.com/api/v4/projects/9/trigger/
builds
30 0
*
*
*
curl
--request
POST
--form
token
=
TOKEN
--form
ref
=
master https://gitlab.example.com/api/v4/projects/9/trigger/
pipeline
```
[
ci-229
]:
https://gitlab.com/gitlab-org/gitlab-ci/merge_requests/229
lib/api/entities.rb
View file @
140b51ce
...
...
@@ -639,7 +639,9 @@ module API
end
class
Trigger
<
Grape
::
Entity
expose
:token
,
:created_at
,
:updated_at
,
:deleted_at
,
:last_used
expose
:token
,
:description
expose
:created_at
,
:updated_at
,
:deleted_at
,
:last_used
expose
:owner
,
using:
Entities
::
UserBasic
end
class
Variable
<
Grape
::
Entity
...
...
lib/api/triggers.rb
View file @
140b51ce
...
...
@@ -7,7 +7,7 @@ module API
end
resource
:projects
do
desc
'Trigger a GitLab project pipeline'
do
success
Entities
::
TriggerRequest
success
Entities
::
Pipeline
end
params
do
requires
:ref
,
type:
String
,
desc:
'The commit sha or name of a branch or tag'
...
...
@@ -31,7 +31,7 @@ module API
if
trigger_request
present
trigger_request
.
pipeline
,
with:
Entities
::
Pipeline
else
errors
=
'No pipeline create'
errors
=
'No pipeline create
d
'
render_api_error!
(
errors
,
400
)
end
end
...
...
@@ -61,7 +61,7 @@ module API
authenticate!
authorize!
:admin_build
,
user_project
trigger
=
user_project
.
triggers
.
find
(
params
[
:trigger_id
]
)
trigger
=
user_project
.
triggers
.
find
(
params
.
delete
(
:trigger_id
)
)
return
not_found!
(
'Trigger'
)
unless
trigger
present
trigger
,
with:
Entities
::
Trigger
...
...
@@ -94,15 +94,18 @@ module API
requires
:trigger_id
,
type:
Integer
,
desc:
'The trigger ID'
optional
:description
,
type:
String
,
desc:
'The trigger description'
end
delete
':id/triggers/:trigger_id'
do
put
':id/triggers/:trigger_id'
do
authenticate!
authorize!
:admin_build
,
user_project
trigger
=
user_project
.
triggers
.
find
(
params
[
:trigger_id
]
)
trigger
=
user_project
.
triggers
.
find
(
params
.
delete
(
:trigger_id
)
)
return
not_found!
(
'Trigger'
)
unless
trigger
trigger
=
trigger
.
update
(
declared_params
(
include_missing:
false
))
present
trigger
,
with:
Entities
::
Trigger
if
trigger
.
update
(
declared_params
(
include_missing:
false
))
present
trigger
,
with:
Entities
::
Trigger
else
render_validation_error!
(
trigger
)
end
end
desc
'Take ownership of trigger'
do
...
...
@@ -115,10 +118,11 @@ module API
authenticate!
authorize!
:admin_build
,
user_project
trigger
=
user_project
.
triggers
.
find
(
params
[
:trigger_id
]
)
trigger
=
user_project
.
triggers
.
find
(
params
.
delete
(
:trigger_id
)
)
return
not_found!
(
'Trigger'
)
unless
trigger
if
trigger
.
update
(
owner:
current_user
)
status
:ok
present
trigger
,
with:
Entities
::
Trigger
else
render_validation_error!
(
trigger
)
...
...
@@ -135,7 +139,7 @@ module API
authenticate!
authorize!
:admin_build
,
user_project
trigger
=
user_project
.
triggers
.
find
(
params
[
:trigger_id
]
)
trigger
=
user_project
.
triggers
.
find
(
params
.
delete
(
:trigger_id
)
)
return
not_found!
(
'Trigger'
)
unless
trigger
trigger
.
destroy
...
...
spec/requests/api/triggers_spec.rb
View file @
140b51ce
This diff is collapsed.
Click to expand it.
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