Commit ed777c7b authored by Achilleas Pipinellis's avatar Achilleas Pipinellis
Browse files

Merge branch 'ci_triggers_docs' into 'master'

Documentation on CI triggers

Closes #3432

## Notes

* Implement build trigger API -
* Build trigger API -
* Build pipeline - and
* Dependent builds -
* Travis docs -
* Custom variables Circle CI example -
* Triggers API (CI) will be done in a separate MR
* Notify once done

## Docs needed to change

- [x] `doc/ci/`
- [x] `doc/`

See merge request !2161
parents 92bc7038 662e9cff
...@@ -28,17 +28,18 @@ ...@@ -28,17 +28,18 @@
- [Using SSH keys](ci/ssh_keys/ - [Using SSH keys](ci/ssh_keys/
- [User permissions](ci/permissions/ - [User permissions](ci/permissions/
- [API](ci/api/ - [API](ci/api/
- [Triggering builds through the API](ci/triggers/
### CI Languages ### CI Languages
+ [Testing PHP](ci/languages/ - [Testing PHP](ci/languages/
### CI Services ### CI Services
+ [Using MySQL](ci/services/ - [Using MySQL](ci/services/
+ [Using PostgreSQL](ci/services/ - [Using PostgreSQL](ci/services/
+ [Using Redis](ci/services/ - [Using Redis](ci/services/
+ [Using Other Services](ci/docker/ - [Using Other Services](ci/docker/
### CI Examples ### CI Examples
...@@ -2,25 +2,26 @@ ...@@ -2,25 +2,26 @@
### User documentation ### User documentation
+ [Quick Start](quick_start/ * [Quick Start](quick_start/
+ [Configuring project (.gitlab-ci.yml)](yaml/ * [Configuring project (.gitlab-ci.yml)](yaml/
+ [Configuring runner](runners/ * [Configuring runner](runners/
+ [Configuring deployment](deployment/ * [Configuring deployment](deployment/
+ [Using Docker Images](docker/ * [Using Docker Images](docker/
+ [Using Docker Build](docker/ * [Using Docker Build](docker/
+ [Using Variables](variables/ * [Using Variables](variables/
+ [Using SSH keys](ssh_keys/ * [Using SSH keys](ssh_keys/
* [Triggering builds through the API](triggers/
### Languages ### Languages
+ [Testing PHP](languages/ * [Testing PHP](languages/
### Services ### Services
+ [Using MySQL](services/ * [Using MySQL](services/
+ [Using PostgreSQL](services/ * [Using PostgreSQL](services/
+ [Using Redis](services/ * [Using Redis](services/
+ [Using Other Services](docker/ * [Using Other Services](docker/
### Examples ### Examples
...@@ -32,5 +33,5 @@ ...@@ -32,5 +33,5 @@
### Administrator documentation ### Administrator documentation
+ [User permissions](permissions/ * [User permissions](permissions/
+ [API](api/ * [API](api/
# Triggering Builds through the API
_**Note:** This feature was [introduced][ci-229] in GitLab CE 7.14_
Triggers can be used to force a rebuild of a specific branch, tag or commit,
with an API call.
## Add a trigger
You can add a new trigger by going to your project's **Settings > Triggers**.
The **Add trigger** button will create a new token which you can then use to
trigger a rebuild of this particular project.
Once at least one trigger is created, on the **Triggers** page you will find
some descriptive information on how you can
Every new trigger you create, gets assigned a different token which you can
then use inside your scripts or `.gitlab-ci.yml`. You also have a nice
overview of the time the triggers were last used.
![Triggers page overview](img/triggers_page.png)
## Revoke a trigger
You can revoke a trigger any time by going at your project's
**Settings > Triggers** and hitting the **Revoke** button. The action is
## Trigger a build
To trigger a build you need to send a `POST` request to GitLab's API endpoint:
POST /projects/:id/trigger/builds
The required parameters are the trigger's `token` and the Git `ref` on which
the trigger will be performed. Valid refs are the branch, the tag or the commit
SHA. The `:id` of a project can be found by [querying the API](../api/
or by visiting the **Triggers** page which provides self-explanatory examples.
When a rebuild is triggered, the information is exposed in GitLab's UI under
the **Builds** page and the builds are marked as `triggered`.
![Marked rebuilds as triggered on builds page](img/builds_page.png)
You can see which trigger caused the rebuild by visiting the single build page.
The token of the trigger is exposed in the UI as you can see from the image
![Marked rebuilds as triggered on a single build page](img/trigger_single_build.png)
See the [Examples](#examples) section for more details on how to actually
trigger a rebuild.
## Pass build variables to a trigger
You can pass any number of arbitrary variables in the trigger API call and they
will be available in GitLab CI so that they can be used in your `.gitlab-ci.yml`
file. The parameter is of the form:
This information is also exposed in the UI.
![Build variables in UI](img/trigger_variables.png)
See the [Examples](#examples) section below for more details.
## Examples
Using cURL you can trigger a rebuild with minimal effort, for example:
curl -X POST \
-F token=TOKEN \
-F ref=master \
In this case, the project with ID `9` will get rebuilt on `master` branch.
### Triggering a build within `.gitlab-ci.yml`
You can also benefit by using triggers in your `.gitlab-ci.yml`. Let's say that
you have two projects, A and B, and you want to trigger a rebuild on the `master`
branch of project B whenever a tag on project A is created. This is the job you
need to add in project's A `.gitlab-ci.yml`:
stage: deploy
- "curl -X POST -F token=TOKEN -F ref=master"
- tags
Now, whenever a new tag is pushed on project A, the build will run and the
`build_docs` job will be executed, triggering a rebuild of project B. The
`stage: deploy` ensures that this job will run only after all jobs with
`stage: test` complete successfully.
_**Note:** If your project is public, passing the token in plain text is
probably not the wiser idea, so you might want to use a
[secure variable](../variables/
for that purpose._
### Making use of trigger variables
Using trigger variables can be proven useful for a variety of reasons.
* Identifiable jobs. Since the variable is exposed in the UI you can know
why the rebuild was triggered if you pass a variable that explains the
* Conditional job processing. You can have conditional jobs that run whenever
a certain variable is present.
Consider the following `.gitlab-ci.yml` where we set three
[stages](../yaml/ and the `upload_package` job is run only
when all jobs from the test and build stages pass. When the `UPLOAD_TO_S3`
variable is non-zero, `make upload` is run.
- test
- build
- package
- make test
stage: build
- make build
stage: package
- if [ -n "${UPLOAD_TO_S3}" ]; then make upload; fi
You can then trigger a rebuild while you pass the `UPLOAD_TO_S3` variable
and the script of the `upload_package` job will run:
curl -X POST \
-F token=TOKEN \
-F ref=master \
-F "variables[UPLOAD_TO_S3]=true" \
### Using cron to trigger nightly builds
Whether you craft a script or just run cURL directly, you can trigger builds
in conjunction with cron. The example below triggers a build on the `master`
branch of project with ID `9` every night at `00:30`:
30 0 * * * curl -X POST -F token=TOKEN -F ref=master
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment