BigW Consortium Gitlab

enviroments.md 3.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
# Environments

## List environments

Get all environments for a given project.

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

| Attribute | Type    | Required | Description           |
| --------- | ------- | -------- | --------------------- |
| `id`      | integer | yes      | The ID of the project |

```bash
16
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/1/environments
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
```

Example response:

```json
[
  {
    "id": 1,
    "name": "Env1",
    "external_url": "https://env1.example.gitlab.com"
  }
]
```

## Create a new environment

Creates a new environment with the given name and external_url.

35
It returns 201 if the environment was successfully created, 400 for wrong parameters.
36 37 38 39 40 41 42 43 44

```
POST /projects/:id/environment
```

| Attribute     | Type    | Required | Description                  |
| ------------- | ------- | -------- | ---------------------------- |
| `id`          | integer | yes      | The ID of the project        |
| `name`        | string  | yes      | The name of the environment  |
Z.J. van de Weg committed
45
| `external_url` | string  | no     | Place to link to for this environment |
46 47

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

Example response:

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

61
## Edit an existing environment
62

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

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

```
68
PUT /projects/:id/environments/:environments_id
69 70
```

71 72 73 74 75 76
| Attribute       | Type    | Required                          | Description                      |
| --------------- | ------- | --------------------------------- | -------------------------------  |
| `id`            | integer | yes                               | The ID of the project            |
| `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             |
77 78

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

Example response:

```json
{
  "id": 1,
87 88
  "name": "staging",
  "external_url": "https://staging.example.gitlab.com"
89 90 91
}
```

92
## Delete an environment
93

94
It returns 200 if the environment was successfully deleted, and 404 if the environment does not exist.
95 96

```
97
DELETE /projects/:id/environments/:environment_id
98 99
```

100 101 102 103
| Attribute | Type    | Required | Description           |
| --------- | ------- | -------- | --------------------- |
| `id` | integer | yes | The ID of the project |
| `environment_id` | integer | yes | The ID of the environment |
104 105

```bash
106
curl --request DELETE --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" "https://gitlab.example.com/api/v3/projects/1/environment/1"
107 108 109 110 111 112 113
```

Example response:

```json
{
  "id": 1,
114 115
  "name": "deploy",
  "external_url": "https://deploy.example.gitlab.com"
116 117
}
```