BigW Consortium Gitlab

deploy_key_multiple_projects.md 1013 Bytes
Newer Older
1
# Adding deploy keys to multiple projects via API
2

3 4
If you want to easily add the same deploy key to multiple projects in the same
group, this can be achieved quite easily with the API.
5

6 7
First, find the ID of the projects you're interested in, by either listing all
projects:
8 9

```
10
curl --header 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' https://gitlab.example.com/api/v4/projects
11 12
```

13
Or finding the ID of a group and then listing all projects in that group:
14 15

```
16
curl --header 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' https://gitlab.example.com/api/v4/groups
17

Job van der Voort committed
18
# For group 1234:
19
curl --header 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' https://gitlab.example.com/api/v4/groups/1234
20 21 22
```

With those IDs, add the same deploy key to all:
23

24
```
25
for project_id in 321 456 987; do
26
    curl --request POST --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" --header "Content-Type: application/json" \
27
    --data '{"title": "my key", "key": "ssh-rsa AAAA..."}' https://gitlab.example.com/api/v4/projects/${project_id}/deploy_keys
28
done
29
```