Configuring a GitLab Runner for continuous integration pipelines
TypeScriptTo configure a GitLab Runner using Pulumi, we'll create a new instance of a GitLab Runner, which is used to run your CI/CD jobs and send the results back to GitLab. GitLab Runners can be specific to certain projects or available for every project in GitLab. They can run on your local machine, in a Docker container, or on a cloud server.
Here's how you can do this using Pulumi and the GitLab provider:
-
First, you'll need a GitLab registration token for your runner, which you can get from your GitLab instance's admin area (usually under
/admin/runners
). -
Next, we'll define a new GitLab Runner resource using Pulumi, providing the necessary configuration such as description, tags, and the registration token.
The following program is written in TypeScript and will get you started with setting up a GitLab Runner:
import * as gitlab from "@pulumi/gitlab"; // Replace the token with your GitLab Runner registration token. const registrationToken = "YOUR_REGISTRATION_TOKEN"; // Create a new GitLab Runner const runner = new gitlab.Runner("example-runner", { description: "An example GitLab Runner", active: true, // Specify if the runner is active tagList: ["docker", "production"], // Tags to help organize runners locked: false, // When a runner is locked, it cannot be assigned to other projects runUntagged: false, // Specify if this runner can run jobs without tags accessLevel: "not_protected", // "not_protected" to allow public projects to use the runner, "ref_protected" for protected branches and tags only registrationToken: registrationToken, // The registration token from your GitLab instance }); // Export the runner's ID export const runnerId = runner.id;
In this program:
- We import the GitLab provider from
@pulumi/gitlab
. - We provide a registration token, which you must replace with the actual token from your GitLab instance.
- We create a new runner with some basic configurations: - The
description
is a human-readable description of the runner. - The
tagList
is an array of tags that you can use to select runners based on the job requirements. locked
determines if the runner is dedicated or can be used by other projects.runUntagged
determines if the runner can execute jobs that don't have tags associated with them.accessLevel
sets the runners' visibility level.registrationToken
authenticates the runner with the GitLab instance.
Please note that the actual token has been masked for security purposes. You need to replace "YOUR_REGISTRATION_TOKEN" with your real GitLab Runner registration token.
Remember, you'll need to have Pulumi installed and configured your GitLab provider credentials (
GITLAB_TOKEN
) correctly to apply this configuration. Once ready, you can runpulumi up
to provision the runner in your GitLab instance.The
runnerId
exported at the end of the program will provide you with the ID of the created runner, which can be useful for configuring projects to use this runner or for further automation steps.-