Comment trouver l'ID de groupe Gitlab en utilisant l'API Gitlab via python-gitlab

install_python_gitlab.sh
pip install python-gitlab
get_gitlab_group_id.py
import gitlab

def get_gitlab_group_id(group_name, access_token):
    # Initialise une instance GitLab avec votre jeton privé
    gl = gitlab.Gitlab('https://gitlab.com', private_token=access_token)

    # Recherche des groupes par nom
    groups = gl.groups.list(search=group_name)
    for group in groups:
        if group.name == group_name or group.path == group_name:
            return group.id

    raise ValueError("Groupe non trouvé")

# Exemple d'utilisation
group_id = get_gitlab_group_id("Protectors of the Footprint Realm", 'glpat-yykIsrTg6RyKcFAvd2os')

group_id sera un entier, par exemple 6604163


Consultez les articles similaires par catégorie : GitLab Python