Add a Git token to Velocity

Sometimes, a Dockerfile will include a Git clone operation in which you will need to include a Git token as a build argument. For example, if your Dockerfile includes something like the following, you will need to include GH_TOKEN and GH_USERNAME build args.

FROM base_image:example

# Set environment variables for Git token and username
# Pass the token in a Git Clone operation
RUN git clone https://${GH_USERNAME}:${GH_TOKEN} /app

To do so in Velocity, you can pass the GH_TOKEN and GH_USERNAME as a build args in the Velocity Run Configuration Wizard as follows:

NOTE: your Git token is never passed to Velocity, as it remains only in your local machine, and in your Kubernetes cluster during a Velocity build.

Generating a Personal Access Token in GitHub

To generate a Personal Access Token in GitHub, follow the steps shown below:

Storing Git Tokens as Environment Variables

Velocity allows Run Configuration values to be input as environment variables, which are then resolved at runtime. This feature is commonly used to access Git Tokens, which are stored in a developer's local environment.

For example, after generating a Git token, you can store the token as a local environment variable as follows:

export GH_TOKEN=<your-token>

Then, you can pass this environment variable when you create a Velocity Run Configuration, as follows:

Last updated