BigW Consortium Gitlab

environments.md 4.43 KB
Newer Older
1
# Environments API
2 3 4 5 6 7 8 9 10 11 12

## List environments

Get all environments for a given project.

```
GET /projects/:id/environments
```

| Attribute | Type    | Required | Description           |
| --------- | ------- | -------- | --------------------- |
13
| `id`      | integer/string | yes      | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
14 15

```bash
16
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/projects/1/environments
17 18 19 20 21 22 23 24
```

Example response:

```json
[
  {
    "id": 1,
Nick Thomas committed
25 26 27
    "name": "review/fix-foo",
    "slug": "review-fix-foo-dfjre3",
    "external_url": "https://review-fix-foo-dfjre3.example.gitlab.com"
28 29 30 31 32 33 34 35
  }
]
```

## Create a new environment

Creates a new environment with the given name and external_url.

36
It returns `201` if the environment was successfully created, `400` for wrong parameters.
37 38

```
39
POST /projects/:id/environments
40 41 42 43
```

| Attribute     | Type    | Required | Description                  |
| ------------- | ------- | -------- | ---------------------------- |
44
| `id`          | integer/string | yes      | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user        |
45
| `name`        | string  | yes      | The name of the environment  |
Z.J. van de Weg committed
46
| `external_url` | string  | no     | Place to link to for this environment |
47 48

```bash
49
curl --data "name=deploy&external_url=https://deploy.example.gitlab.com" --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/environments"
50 51 52 53 54 55 56 57
```

Example response:

```json
{
  "id": 1,
  "name": "deploy",
Nick Thomas committed
58
  "slug": "deploy",
59 60 61 62
  "external_url": "https://deploy.example.gitlab.com"
}
```

63
## Edit an existing environment
64

65 66
Updates an existing environment's name and/or external_url.

67
It returns `200` if the environment was successfully updated. In case of an error, a status code `400` is returned.
68 69

```
70
PUT /projects/:id/environments/:environments_id
71 72
```

73 74
| Attribute       | Type    | Required                          | Description                      |
| --------------- | ------- | --------------------------------- | -------------------------------  |
75
| `id`            | integer/string | yes                               | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user            |
76 77 78
| `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             |
79 80

```bash
81
curl --request PUT --data "name=staging&external_url=https://staging.example.gitlab.com" --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/environments/1"
82 83 84 85 86 87 88
```

Example response:

```json
{
  "id": 1,
89
  "name": "staging",
Nick Thomas committed
90
  "slug": "staging",
91
  "external_url": "https://staging.example.gitlab.com"
92 93 94
}
```

95
## Delete an environment
96

97
It returns `204` if the environment was successfully deleted, and `404` if the environment does not exist.
98 99

```
100
DELETE /projects/:id/environments/:environment_id
101 102
```

103 104
| Attribute | Type    | Required | Description           |
| --------- | ------- | -------- | --------------------- |
105
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
106
| `environment_id` | integer | yes | The ID of the environment |
107 108

```bash
109
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v4/projects/1/environments/1"
110
```
111 112 113 114 115 116 117 118 119 120 121

## 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           |
| --------- | ------- | -------- | --------------------- |
122
| `id` | integer/string | yes | The ID or [URL-encoded path of the project](README.md#namespaced-path-encoding) owned by the authenticated user |
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| `environment_id` | integer | yes | The ID of the environment |

```bash
curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/environments/1/stop"
```

Example response:

```json
{
  "id": 1,
  "name": "deploy",
  "slug": "deploy",
  "external_url": "https://deploy.example.gitlab.com"
}
```