Useful Gitlab Clone Repo Tree
If you have been reading my blog and you know me, I always try to seek and look for improvements, and the way to go could be learning new things with fresh knowledge, a good way to improve 1% every day your technical and personal skills; There are times, situations and needs certainly that require that a DevOps moves from one squad to another squad.
This happened to me recently and one of the tasks that you need to do after moving from one team to another is to properly clone and download app repos and infrastructure repos(infra,sec,o11y, and so on..) to do an offline code review. Well my post today is to save something that I had to learn from the official docs of the new glab cli tool.
Gitlab currently have his own cli tool to interact with the gitlab api called glab
.
Written in Go, glab was created in July 2020 by Ghanaian software engineer Clement Sam, and has been worked on by over 80 contributors since. Its goal is to deliver similar functionality to the GitHub CLI tool ‘gh’. This includes working with GitLab issues and merge requests, and watching pipelines running directly from the CLI. glab works with both the SaaS product, and with self-hosted GitLab installations. The GitLab CLI uses commands structured like glab [flags] to perform many of the tasks normally actioned from the GitLab user interface.
Installing the glab command can be accomplished running the following command :
$brew install glab
So lets assume that you need to clone a few mono repos of a group called finance. Using gitlab as a self hosted version when you create a group, repo gitlab is going to assign a unique ID number per group, per repo.
Now if you run the following command on your machine
$glab repo clone -g 3051
you’re going to get :
GET https://gitlab.com/api/v4/user: 401 {message: 401 Unauthorized}
This is because by default the cli tool looks for the default host https://gitlab.com/
so then the solution should be exporting the environment variable pointing to the private Gitlab enterprise instance :
$export GITLAB_HOST="https://gitlab.domain.com"
$glab repo clone -g 3051
With that you will be able to download all the repos inside a group.
H