Private GitLab repos as dependencies
Prerequisites
- A private GitLab repo
- that is set up as a dependency
How to
- configure gitlab so it can be accessed despite being private
- and add it to a project
1. Configuring gitlab access
To allow third parties to use this dependency without giving them access to your entire gitlab account you can use a gitlab deploy token specific to the dependency repo.
You create the READ ONLY deploy token in the gitlab ui at repo > settings > repository > expand > deploy tokens. Make note of both the token name and the token.
2. Adding the dependency to a node project
The syntax for the url we need to add to the project is
git+https://{token-name}:{token}@gitlab.com/{Username}/{Repository}#{branch|tag}
We add it with yarn or npm, like with this example:
$ yarn add git+https://gitlab+deploy-token-84004:i43pm4EmzXQD6DLSzbsj@gitlab.com/djurensratt/labs/npm-module-test.git#master
Which adds it to packages.json:
// packages.json
// ...
"dependencies": {
"npm-module-test": "git+https://gitlab+deploy-token-84004:i43pm4EmzXQD6DLSzbsj@gitlab.com/djurensratt/labs/npm-module-test.git#master"
}
// ...
Examples
References
- Adding private GitLab repos with a deploy token Stack Overflow
- Creating deploy tokens GitLab documentation
- Creating npm modules NPM documentation: