如何根据gitlab用户id获取gitlab用户名

How to get gitlab username based on gitlab user id

对于一个项目,我是 运行 提供服务器并配置它们的管道。在服务器配置中,需要添加gitlab用户名。我特别需要用户名,因为这不是基于 gitlab 用户 ID 或用户邮件(所以我不能只使用 gitlab_user_email 变量并从那里导出用户名)。

有没有办法通过他们的 gitlab 用户 ID 获取用户的用户名?

是的,您可以从 api 端点 for user

获取用户详细信息,包括 username
GET /users/:id

#curl example for gitlab.com
curl "https://gitlab.com/api/v4/users/<user id>?access_token=<your gitlab token>"