Reputation: 3076
I have a GitLab CE server with many projects and I would like to add a user to all projects.
I want to avoid having to do this through the UI (Project -> Settings -> Member -> Add User to Project) if possible as that will take a significant amount of time.
Upvotes: 7
Views: 5293
Reputation: 1
If that is for audit consider an Auditor access level. https://docs.gitlab.com/ee/administration/auditor_users.html
Upvotes: 0
Reputation: 2034
You could use the GitLab Projects and Members API to achieve this.
First do a GET
request against the /projects
API to get a list of all projects.
Then do a POST
against the/projects/:id/members
API for each project you want to add the member to.
You can see an example of the POST
request on that page
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --data "user_id=1&access_level=30" https://gitlab.example.com/api/v4/projects/:id/members
Upvotes: 4
Reputation: 6711
One way to do this is to move all of the project under a group. Then adding a new member to the group will grant them access to all of the contained projects. It may be tedious to move all of the projects, but once it is done, it will make member management easier. Also consider making a nested hierarchy of groups if you expect you may want finer-grained permissions in the future.
See https://docs.gitlab.com/ce/user/group for instructions.
From the "Add users to a group" section of the linked page:
A benefit of putting multiple projects in one group is that you can give a user to access to all projects in the group with one action.
Add members to a group by navigating to the group’s dashboard and clicking Members.
Select the permission level, and add the new member. You can also set the expiring date for that user; this is the date on which they will no longer have access to your group.
Consider a group with two projects:
- On the Group Members page, you can now add a new user to the group.
- Now, because this user is a Developer member of the group, they automatically gets Developer access to all projects within that group.
To increase the access level of an existing user for a specific project, add them again as a new member to the project with the desired permission level.
Upvotes: 6