Automate retrieval of Sonarcloud user details before joining Organization

Background: My team uses SonarCloud with GitLab authentication. We have a script that automates user onboarding. The user must log in to SonarCloud to create their Sonarcloud user. Once this is done, the next time the script runs it will add users to our SonarCloud organization and the relevant teams they need to be part of based on their GitLab permissions. This works on the assumption that the user’s GitLab username will match their SonarCloud username.

Issue: Recently, SonarCloud seems to have introduced a change that means new users logging into SonarCloud for the first time receive a username of ‘gitlabusername-randomstring@gitlab’, rather than just ‘gitlabusername@gitlab’. This breaks our automation, as we can no longer add users to our organization in SonarCloud based on their GitLab usernames. We would really like to avoid having to manually maintain a list of SonarCloud usernames. Can you suggest any ways to deal with this?

Hello @RachelT,

Welcome to the community.

What I would recommend is to use the users/users API. You can find the user login by passing the email address of the user, and from the response, you could filter for externalProvider : gitlab to filter the user.

Hope this helps.

Cheers,
Sarath