Code Studio

Pulling private repos as git submodules in Code Studio

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

  1. Log in to GitHub.
  2. Go to Settings > Developer settings > Personal access tokens > Tokens (classic).
  3. Select Generate new token > Generate new token (classic).
  4. Select an expiration period.
  5. In Select scopes, select all items under repo.

  6. 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.

  1. 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.

  2. 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

While defining git submodules in the .gitmodules file or in the git submodule add command, use SSH repository URLs if you use SSH URLs for local development. The pipeline replaces the SSH URLs with HTTPS URLs to authenticate with GitHub.

Help

Ask a question

Common questions

If you can't find what you're looking for, then you can reach out to our Support team for further assistance.