In certain cases, you might need to pull a git submodule from a private repository into your Code Studio project.
This tutorial demonstrates how to authenticate with a private GitHub repository and pull the git submodule into your Build Code job.
Generating a GitHub personal access token¶
- Log in to GitHub.
- Go to Settings > Developer settings > Personal access tokens > Tokens (classic).
- Select Generate new token > Generate new token (classic).
- Select an expiration period.
In Select scopes, select all items under repo.
- Select Generate token and copy the token.
Adding GitHub authentication to the Build Code job¶
To authenticate with GitHub, use before_script to hook into the Build Code job. To use before_script, you require a custom gitlab-ci.yml file.
Add the GITHUB_TOKEN
environment variable to Code Studio and set its value to the token that you copied from GitHub.
For more information, see Adding environment variables.
Add a before_script to the Build Code job in your project’s gitlab-ci.yml
file:
"Build Code":
before_script:
- |
# Manually trigger the submodule update
git config --global url."https://x-access-token:${GITHUB_TOKEN}@github.com/".insteadOf [email protected]:
git submodule update --init --recursive