debian-mirror-gitlab/doc/api/environments.md

139 lines
4.4 KiB
Markdown
Raw Normal View History

2017-09-10 17:25:29 +05:30
# Environments API
2016-09-13 17:45:13 +05:30
## List environments
Get all environments for a given project.
```
GET /projects/:id/environments
```
| Attribute | Type | Required | Description |
| --------- | ------- | -------- | --------------------- |
2017-08-17 22:00:37 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
2016-09-13 17:45:13 +05:30
```bash
2019-02-13 22:33:31 +05:30
curl --header "PRIVATE-TOKEN: <your_access_token>" https://gitlab.example.com/api/v4/projects/1/environments
2016-09-13 17:45:13 +05:30
```
Example response:
```json
[
{
"id": 1,
2017-08-17 22:00:37 +05:30
"name": "review/fix-foo",
"slug": "review-fix-foo-dfjre3",
"external_url": "https://review-fix-foo-dfjre3.example.gitlab.com"
2016-09-13 17:45:13 +05:30
}
]
```
## Create a new environment
Creates a new environment with the given name and external_url.
2017-08-17 22:00:37 +05:30
It returns `201` if the environment was successfully created, `400` for wrong parameters.
2016-09-13 17:45:13 +05:30
```
2018-03-17 18:26:18 +05:30
POST /projects/:id/environments
2016-09-13 17:45:13 +05:30
```
| Attribute | Type | Required | Description |
| ------------- | ------- | -------- | ---------------------------- |
2017-08-17 22:00:37 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
2016-09-13 17:45:13 +05:30
| `name` | string | yes | The name of the environment |
| `external_url` | string | no | Place to link to for this environment |
```bash
2019-02-13 22:33:31 +05:30
curl --data "name=deploy&external_url=https://deploy.example.gitlab.com" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/environments"
2016-09-13 17:45:13 +05:30
```
Example response:
```json
{
"id": 1,
"name": "deploy",
2017-08-17 22:00:37 +05:30
"slug": "deploy",
2016-09-13 17:45:13 +05:30
"external_url": "https://deploy.example.gitlab.com"
}
```
## Edit an existing environment
Updates an existing environment's name and/or external_url.
2017-08-17 22:00:37 +05:30
It returns `200` if the environment was successfully updated. In case of an error, a status code `400` is returned.
2016-09-13 17:45:13 +05:30
```
PUT /projects/:id/environments/:environments_id
```
| Attribute | Type | Required | Description |
| --------------- | ------- | --------------------------------- | ------------------------------- |
2017-08-17 22:00:37 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
2016-09-13 17:45:13 +05:30
| `environment_id` | integer | yes | The ID of the environment | The ID of the environment |
| `name` | string | no | The new name of the environment |
| `external_url` | string | no | The new external_url |
```bash
2019-02-13 22:33:31 +05:30
curl --request PUT --data "name=staging&external_url=https://staging.example.gitlab.com" --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/environments/1"
2016-09-13 17:45:13 +05:30
```
Example response:
```json
{
"id": 1,
"name": "staging",
2017-08-17 22:00:37 +05:30
"slug": "staging",
2016-09-13 17:45:13 +05:30
"external_url": "https://staging.example.gitlab.com"
}
```
## Delete an environment
2018-03-17 18:26:18 +05:30
It returns `204` if the environment was successfully deleted, and `404` if the environment does not exist.
2016-09-13 17:45:13 +05:30
```
DELETE /projects/:id/environments/:environment_id
```
| Attribute | Type | Required | Description |
| --------- | ------- | -------- | --------------------- |
2017-08-17 22:00:37 +05:30
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
2016-09-13 17:45:13 +05:30
| `environment_id` | integer | yes | The ID of the environment |
```bash
2019-02-13 22:33:31 +05:30
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/environments/1"
2017-08-17 22:00:37 +05:30
```
## Stop an environment
It returns `200` if the environment was successfully stopped, and `404` if the environment does not exist.
```
POST /projects/:id/environments/:environment_id/stop
```
| Attribute | Type | Required | Description |
| --------- | ------- | -------- | --------------------- |
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
| `environment_id` | integer | yes | The ID of the environment |
```bash
2019-02-13 22:33:31 +05:30
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/1/environments/1/stop"
2016-09-13 17:45:13 +05:30
```
Example response:
```json
{
"id": 1,
"name": "deploy",
2017-08-17 22:00:37 +05:30
"slug": "deploy",
2016-09-13 17:45:13 +05:30
"external_url": "https://deploy.example.gitlab.com"
}
```