gitlab-org--gitlab-foss/doc/api/deploy_key_multiple_projects.md
Alejandro Rodríguez 818ad89ea5 Add /deploy_keys API to retrieve all deploy keys regardless of project affiliation
Also, in favour of consistency, deprecate `/projects/:id/keys/...` routes in favour of
`/projects/:id/deploy_keys/...`
2016-07-20 13:39:19 -04:00

968 B

Adding deploy keys to multiple projects

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.

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

curl -H 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' https://gitlab.example.com/api/v3/projects

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

curl -H 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' https://gitlab.example.com/api/v3/groups

# For group 1234:
curl -H 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' https://gitlab.example.com/api/v3/groups/1234

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

for project_id in 321 456 987; do
    curl -X POST -H "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" -H "Content-Type: application/json" \
    --data '{"title": "my key", "key": "ssh-rsa AAAA..."}' https://gitlab.example.com/api/v3/projects/${project_id}/deploy_keys
done