How to clone all projects of a group at once in GitLab?

后端 未结 15 1523
[愿得一人]
[愿得一人] 2020-12-23 02:02

In my GitLab repository, I have a group with 20 projects. I want to clone all projects at once. Is that possible?

15条回答
  •  不知归路
    2020-12-23 02:53

    Yep it's possible, here is the code.

    prerequisites:

    pip install python-gitlab

    #!/usr/bin/python3
    import os
    import sys
    import gitlab
    import subprocess
    
    glab = gitlab.Gitlab(f'https://{sys.argv[1]}', f'{sys.argv[3]}')
    groups = glab.groups.list()
    groupname = sys.argv[2]
    for group in groups:
        if group.name == groupname:
            projects = group.projects.list(all=True)
    
    for repo in projects:
        command = f'git clone {repo.ssh_url_to_repo}'
        process = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
        output, _ = process.communicate()
        process.wait()
    

    Example:

    • create .py file (ex. gitlab-downloader.py)
    • copy-paste code from above
    • on Linux OS (or OSX) do chmod +x on the script file (ex. chmod +x gitlab-downloader.py)
    • run it with 3 params: Gitlab hostname, groupname, your Personal Access Token(see https://gitlab.exmaple.com/profile/personal_access_tokens)

提交回复
热议问题