Using private Git repositories
During the build process, it might be necessary to access other private repositories containing, for instance, libraries.
In case such repositories do not belong to the same user that can clone the main application codebase, it is possible to use git credentials codebase.
How to use Git Credentials
The first step is to generate a personal access token: see the github or bitbucket documentation.
Then build an url for the Git Credentials.
The URL for GitHub looks like:
https://<username>:<token>@github.com
while for Bitbucket looks like:
https://<username>:<token>@bitbucket.org
and GitLab looks like:
https://<username>:<token>@gitlab.com
where the username
is the username of the account used to generate the token.
You cannot add Git credentials for the same provider that your repository is hosted on. For instance, if your repository is hosted on GitHub and you add additional Git credentials for a GitHub user then the additional credentials will be ignored.
Finally add a secret inside an environment
with key called GIT_CREDENTIALS
and for the value use the url created before.
At this point, if you use this environment during a build, you can access your repository specifying the https
clone url without any token.
For instance, if your private repo contains an npm library, the package.json
would reference it in this way:
{
...
"dependencies": {
"my_super_secret_library": "git+https://bitbucket.org/myorg/my_super_secret_library.git",
...,
}
...
}