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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
ff8194e0
Commit
ff8194e0
authored
Nov 07, 2016
by
Dmitry Poray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ref parameter for triggerring builds with gitlab webhook from other project.
parent
c5e147de
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
61 additions
and
4 deletions
+61
-4
app/helpers/triggers_helper.rb
app/helpers/triggers_helper.rb
+6
-2
app/views/projects/triggers/index.html.haml
app/views/projects/triggers/index.html.haml
+19
-1
changelogs/unreleased/23584-triggering-builds-from-webhooks.yml
...logs/unreleased/23584-triggering-builds-from-webhooks.yml
+4
-0
doc/ci/triggers/README.md
doc/ci/triggers/README.md
+24
-0
lib/api/triggers.rb
lib/api/triggers.rb
+1
-1
spec/requests/api/triggers_spec.rb
spec/requests/api/triggers_spec.rb
+7
-0
No files found.
app/helpers/triggers_helper.rb
View file @
ff8194e0
module
TriggersHelper
module
TriggersHelper
def
builds_trigger_url
(
project_id
)
def
builds_trigger_url
(
project_id
,
ref:
nil
)
"
#{
Settings
.
gitlab
.
url
}
/api/v3/projects/
#{
project_id
}
/trigger/builds"
if
ref
.
nil?
"
#{
Settings
.
gitlab
.
url
}
/api/v3/projects/
#{
project_id
}
/trigger/builds"
else
"
#{
Settings
.
gitlab
.
url
}
/api/v3/projects/
#{
project_id
}
/ref/
#{
ref
}
/trigger/builds"
end
end
end
end
end
app/views/projects/triggers/index.html.haml
View file @
ff8194e0
...
@@ -75,6 +75,16 @@
...
@@ -75,6 +75,16 @@
stage: deploy
stage: deploy
script:
script:
- "curl -X POST -F token=TOKEN -F ref=REF_NAME
#{
builds_trigger_url
(
@project
.
id
)
}
"
- "curl -X POST -F token=TOKEN -F ref=REF_NAME
#{
builds_trigger_url
(
@project
.
id
)
}
"
%h5
.prepend-top-default
Use webhook
%p
.light
Add the following webhook to another project for Push and Tag push events.
The project will be rebuilt at the corresponding event.
%pre
:plain
#{
builds_trigger_url
(
@project
.
id
,
ref:
'REF_NAME'
)
}
?token=TOKEN
%h5
.prepend-top-default
%h5
.prepend-top-default
Pass build variables
Pass build variables
...
@@ -83,10 +93,18 @@
...
@@ -83,10 +93,18 @@
%code
variables[VARIABLE]=VALUE
%code
variables[VARIABLE]=VALUE
to an API request. Variable values can be used to distinguish between triggered builds and normal builds.
to an API request. Variable values can be used to distinguish between triggered builds and normal builds.
%pre
.append-bottom-0
With cURL:
%pre
:plain
:plain
curl -X POST \
curl -X POST \
-F token=TOKEN \
-F token=TOKEN \
-F "ref=REF_NAME" \
-F "ref=REF_NAME" \
-F "variables[RUN_NIGHTLY_BUILD]=true" \
-F "variables[RUN_NIGHTLY_BUILD]=true" \
#{
builds_trigger_url
(
@project
.
id
)
}
#{
builds_trigger_url
(
@project
.
id
)
}
%p
.light
With webhook:
%pre
.append-bottom-0
:plain
#{
builds_trigger_url
(
@project
.
id
,
ref:
'REF_NAME'
)
}
?token=TOKEN&variables[RUN_NIGHTLY_BUILD]=true
changelogs/unreleased/23584-triggering-builds-from-webhooks.yml
0 → 100644
View file @
ff8194e0
---
title
:
Make it possible to trigger builds from webhooks
merge_request
:
7022
author
:
Dmitry Poray
doc/ci/triggers/README.md
View file @
ff8194e0
...
@@ -58,6 +58,22 @@ below.
...
@@ -58,6 +58,22 @@ below.
See the
[
Examples
](
#examples
)
section for more details on how to actually
See the
[
Examples
](
#examples
)
section for more details on how to actually
trigger a rebuild.
trigger a rebuild.
## Trigger a build from webhook
> Introduced in GitLab 8.14.
To trigger a build from webhook of another project you need to add the following
webhook url for Push and Tag push events:
```
https://gitlab.example.com/api/v3/projects/:id/ref/:ref/trigger/builds?token=TOKEN
```
> **Note**:
-
`ref`
should be passed as part of url in order to take precedence over
`ref`
from webhook body that designates the branchref that fired the trigger in the source repository.
-
`ref`
should be url encoded if contains slashes.
## Pass build variables to a trigger
## Pass build variables to a trigger
You can pass any number of arbitrary variables in the trigger API call and they
You can pass any number of arbitrary variables in the trigger API call and they
...
@@ -169,6 +185,14 @@ curl --request POST \
...
@@ -169,6 +185,14 @@ curl --request POST \
https://gitlab.example.com/api/v3/projects/9/trigger/builds
https://gitlab.example.com/api/v3/projects/9/trigger/builds
```
```
### Using webhook to trigger builds
You can add the following webhook to another project in order to trigger a build:
```
https://gitlab.example.com/api/v3/projects/9/ref/master/trigger/builds?token=TOKEN&variables[UPLOAD_TO_S3]=true
```
### Using cron to trigger nightly builds
### Using cron to trigger nightly builds
Whether you craft a script or just run cURL directly, you can trigger builds
Whether you craft a script or just run cURL directly, you can trigger builds
...
...
lib/api/triggers.rb
View file @
ff8194e0
...
@@ -12,7 +12,7 @@ module API
...
@@ -12,7 +12,7 @@ module API
requires
:token
,
type:
String
,
desc:
'The unique token of trigger'
requires
:token
,
type:
String
,
desc:
'The unique token of trigger'
optional
:variables
,
type:
Hash
,
desc:
'The list of variables to be injected into build'
optional
:variables
,
type:
Hash
,
desc:
'The list of variables to be injected into build'
end
end
post
":id/trigger/builds"
do
post
":id/
(ref/:ref/)
trigger/builds"
do
project
=
Project
.
find_with_namespace
(
params
[
:id
])
||
Project
.
find_by
(
id:
params
[
:id
])
project
=
Project
.
find_with_namespace
(
params
[
:id
])
||
Project
.
find_by
(
id:
params
[
:id
])
trigger
=
Ci
::
Trigger
.
find_by_token
(
params
[
:token
].
to_s
)
trigger
=
Ci
::
Trigger
.
find_by_token
(
params
[
:token
].
to_s
)
not_found!
unless
project
&&
trigger
not_found!
unless
project
&&
trigger
...
...
spec/requests/api/triggers_spec.rb
View file @
ff8194e0
...
@@ -54,6 +54,13 @@ describe API::API do
...
@@ -54,6 +54,13 @@ describe API::API do
expect
(
pipeline
.
builds
.
size
).
to
eq
(
5
)
expect
(
pipeline
.
builds
.
size
).
to
eq
(
5
)
end
end
it
'creates builds on webhook from other gitlab repository and branch'
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/ref/master/trigger/builds?token=
#{
trigger_token
}
"
),
{
ref:
'refs/heads/other-branch'
}
end
.
to
change
(
project
.
builds
,
:count
).
by
(
5
)
expect
(
response
).
to
have_http_status
(
201
)
end
it
'returns bad request with no builds created if there\'s no commit for that ref'
do
it
'returns bad request with no builds created if there\'s no commit for that ref'
do
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
ref:
'other-branch'
)
post
api
(
"/projects/
#{
project
.
id
}
/trigger/builds"
),
options
.
merge
(
ref:
'other-branch'
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
...
...
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