GitLab is a free, open-source way to host private .git
repositories but it does not seem to work with Go. When you create a project it generates a URL of the fo
Easiest way with Gitlab
before_script:
- git config --global url."https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/".insteadOf https://gitlab.com/
- go env -w GOPRIVATE=gitlab.com/${CI_PROJECT_NAMESPACE}
See more details here: https://docs.gitlab.com/ee/user/project/new_ci_build_permissions_model.html#dependent-repositories
You can setup your git credentials and Go will use them:
git config credential.helper store
echo https://your-github-username:your-generated-password@github.com >> ~/.git-credentials
The way I usually do it is:
Ensure you are using SSH.
once that's done you can configure your git to use ssh
instead https
If you are using Mac OX. you can run vim ~/.gitconfig and add
[url "git@gitlab.com:"]
insteadOf = https://gitlab.com/
once configured you can run
GOPRIVATE="gitlab.com/your_username_or_group" go get gitlab.com/name_or_group/repo_name
I hope that helps.
GitLab version 11.8+ and Go version 1.13+ will work with BASIC auth by using your GitLab personal token. Go to Settings -> Access Tokens in your Gitlab, add a personal access token or use your existing one. In your ~/.netrc file, add following lines:
machine <your GitLab domain> (e.g. gitlab.com)
login <your GitLab id>
password <your GitLab personal access token>
Then you should be able to do go get locally.
If you need to build it in CI, then add following line in your .gitlab-ci.yml file:
before_script:
- echo -e "machine <your GitLab domain>\nlogin gitlab-ci-token\npassword ${CI_JOB_TOKEN}" > ~/.netrc
For the record, this works outside of go using gitlab 7.3.2 and, as JimB has observed, can be used as a workaround. I find that i do get prompted for username/password, even though an SSH key is registered with gitlab:
git clone http://1.2.3.4/private-developers/project.git
Alternatively i can use the SSH equivalent which, since i have an SSH key registered with gitlab, avoids the prompts:
git clone git@1.2.3.4:private-developers/project.git
Neither works with go currently. A fix may be in 7.9 but i haven't had a chance to test it: upcoming bugfix