Runner
The gitlab.Runner
resource allows to manage the lifecycle of a runner. A runner can either be registered at an instance level or group level. The runner will be registered at a group level if the token used is from a group, or at an instance level if the token used is for the instance. ~ Using this resource will register a runner using the deprecated registration_token
flow. To use the new authentication_token
flow instead, use the gitlab.UserRunner
resource! Upstream API: GitLab REST API docs
Example Usage
import * as pulumi from "@pulumi/pulumi";
import * as gitlab from "@pulumi/gitlab";
import * as local from "@pulumi/local";
// Basic GitLab Group Runner
const myGroup = new gitlab.Group("myGroup", {description: "group that holds the runners"});
const basicRunner = new gitlab.Runner("basicRunner", {registrationToken: myGroup.runnersToken});
// GitLab Runner that runs only tagged jobs
const taggedOnly = new gitlab.Runner("taggedOnly", {
registrationToken: myGroup.runnersToken,
description: "I only run tagged jobs",
runUntagged: false,
tagLists: [
"tag_one",
"tag_two",
],
});
// GitLab Runner that only runs on protected branches
const _protected = new gitlab.Runner("protected", {
registrationToken: myGroup.runnersToken,
description: "I only run protected jobs",
accessLevel: "ref_protected",
});
// Generate a `config.toml` file that you can use to create a runner
// This is the typical workflow for this resource, using it to create an authentication_token which can then be used
// to generate the `config.toml` file to prevent re-registering the runner every time new hardware is created.
const myCustomGroup = new gitlab.Group("myCustomGroup", {description: "group that holds the custom runners"});
const myRunner = new gitlab.Runner("myRunner", {registrationToken: myCustomGroup.runnersToken});
// This creates a configuration for a local "shell" runner, but can be changed to generate whatever is needed.
// Place this configuration file on a server at `/etc/gitlab-runner/config.toml`, then run `gitlab-runner start`.
// See https://docs.gitlab.com/runner/configuration/advanced-configuration.html for more information.
const config = new local.File("config", {
filename: `${path.module}/config.toml`,
content: pulumi.interpolate` concurrent = 1
[[runners]]
name = "Hello Terraform"
url = "https://example.gitlab.com/"
token = "${myRunner.authenticationToken}"
executor = "shell"
`,
});
import pulumi
import pulumi_gitlab as gitlab
import pulumi_local as local
# Basic GitLab Group Runner
my_group = gitlab.Group("myGroup", description="group that holds the runners")
basic_runner = gitlab.Runner("basicRunner", registration_token=my_group.runners_token)
# GitLab Runner that runs only tagged jobs
tagged_only = gitlab.Runner("taggedOnly",
registration_token=my_group.runners_token,
description="I only run tagged jobs",
run_untagged=False,
tag_lists=[
"tag_one",
"tag_two",
])
# GitLab Runner that only runs on protected branches
protected = gitlab.Runner("protected",
registration_token=my_group.runners_token,
description="I only run protected jobs",
access_level="ref_protected")
# Generate a `config.toml` file that you can use to create a runner
# This is the typical workflow for this resource, using it to create an authentication_token which can then be used
# to generate the `config.toml` file to prevent re-registering the runner every time new hardware is created.
my_custom_group = gitlab.Group("myCustomGroup", description="group that holds the custom runners")
my_runner = gitlab.Runner("myRunner", registration_token=my_custom_group.runners_token)
# This creates a configuration for a local "shell" runner, but can be changed to generate whatever is needed.
# Place this configuration file on a server at `/etc/gitlab-runner/config.toml`, then run `gitlab-runner start`.
# See https://docs.gitlab.com/runner/configuration/advanced-configuration.html for more information.
config = local.File("config",
filename=f"{path['module']}/config.toml",
content=my_runner.authentication_token.apply(lambda authentication_token: f""" concurrent = 1
[[runners]]
name = "Hello Terraform"
url = "https://example.gitlab.com/"
token = "{authentication_token}"
executor = "shell"
"""))
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using GitLab = Pulumi.GitLab;
using Local = Pulumi.Local;
return await Deployment.RunAsync(() =>
{
// Basic GitLab Group Runner
var myGroup = new GitLab.Group("myGroup", new()
{
Description = "group that holds the runners",
});
var basicRunner = new GitLab.Runner("basicRunner", new()
{
RegistrationToken = myGroup.RunnersToken,
});
// GitLab Runner that runs only tagged jobs
var taggedOnly = new GitLab.Runner("taggedOnly", new()
{
RegistrationToken = myGroup.RunnersToken,
Description = "I only run tagged jobs",
RunUntagged = false,
TagLists = new[]
{
"tag_one",
"tag_two",
},
});
// GitLab Runner that only runs on protected branches
var @protected = new GitLab.Runner("protected", new()
{
RegistrationToken = myGroup.RunnersToken,
Description = "I only run protected jobs",
AccessLevel = "ref_protected",
});
// Generate a `config.toml` file that you can use to create a runner
// This is the typical workflow for this resource, using it to create an authentication_token which can then be used
// to generate the `config.toml` file to prevent re-registering the runner every time new hardware is created.
var myCustomGroup = new GitLab.Group("myCustomGroup", new()
{
Description = "group that holds the custom runners",
});
var myRunner = new GitLab.Runner("myRunner", new()
{
RegistrationToken = myCustomGroup.RunnersToken,
});
// This creates a configuration for a local "shell" runner, but can be changed to generate whatever is needed.
// Place this configuration file on a server at `/etc/gitlab-runner/config.toml`, then run `gitlab-runner start`.
// See https://docs.gitlab.com/runner/configuration/advanced-configuration.html for more information.
var config = new Local.File("config", new()
{
Filename = $"{path.Module}/config.toml",
Content = myRunner.AuthenticationToken.Apply(authenticationToken => @$" concurrent = 1
[[runners]]
name = ""Hello Terraform""
url = ""https://example.gitlab.com/""
token = ""{authenticationToken}""
executor = ""shell""
"),
});
});
package main
import (
"fmt"
"github.com/pulumi/pulumi-gitlab/sdk/v6/go/gitlab"
"github.com/pulumi/pulumi-local/sdk/go/local"
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
// Basic GitLab Group Runner
myGroup, err := gitlab.NewGroup(ctx, "myGroup", &gitlab.GroupArgs{
Description: pulumi.String("group that holds the runners"),
})
if err != nil {
return err
}
_, err = gitlab.NewRunner(ctx, "basicRunner", &gitlab.RunnerArgs{
RegistrationToken: myGroup.RunnersToken,
})
if err != nil {
return err
}
// GitLab Runner that runs only tagged jobs
_, err = gitlab.NewRunner(ctx, "taggedOnly", &gitlab.RunnerArgs{
RegistrationToken: myGroup.RunnersToken,
Description: pulumi.String("I only run tagged jobs"),
RunUntagged: pulumi.Bool(false),
TagLists: pulumi.StringArray{
pulumi.String("tag_one"),
pulumi.String("tag_two"),
},
})
if err != nil {
return err
}
// GitLab Runner that only runs on protected branches
_, err = gitlab.NewRunner(ctx, "protected", &gitlab.RunnerArgs{
RegistrationToken: myGroup.RunnersToken,
Description: pulumi.String("I only run protected jobs"),
AccessLevel: pulumi.String("ref_protected"),
})
if err != nil {
return err
}
myCustomGroup, err := gitlab.NewGroup(ctx, "myCustomGroup", &gitlab.GroupArgs{
Description: pulumi.String("group that holds the custom runners"),
})
if err != nil {
return err
}
myRunner, err := gitlab.NewRunner(ctx, "myRunner", &gitlab.RunnerArgs{
RegistrationToken: myCustomGroup.RunnersToken,
})
if err != nil {
return err
}
// This creates a configuration for a local "shell" runner, but can be changed to generate whatever is needed.
// Place this configuration file on a server at `/etc/gitlab-runner/config.toml`, then run `gitlab-runner start`.
// See https://docs.gitlab.com/runner/configuration/advanced-configuration.html for more information.
_, err = local.NewFile(ctx, "config", &local.FileArgs{
Filename: pulumi.String(fmt.Sprintf("%v/config.toml", path.Module)),
Content: myRunner.AuthenticationToken.ApplyT(func(authenticationToken string) (string, error) {
return fmt.Sprintf(` concurrent = 1
[[runners]]
name = "Hello Terraform"
url = "https://example.gitlab.com/"
token = "%v"
executor = "shell"
`, authenticationToken), nil
}).(pulumi.StringOutput),
})
if err != nil {
return err
}
return nil
})
}
package generated_program;
import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.gitlab.Group;
import com.pulumi.gitlab.GroupArgs;
import com.pulumi.gitlab.Runner;
import com.pulumi.gitlab.RunnerArgs;
import com.pulumi.local.File;
import com.pulumi.local.FileArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
Pulumi.run(App::stack);
}
public static void stack(Context ctx) {
// Basic GitLab Group Runner
var myGroup = new Group("myGroup", GroupArgs.builder()
.description("group that holds the runners")
.build());
var basicRunner = new Runner("basicRunner", RunnerArgs.builder()
.registrationToken(myGroup.runnersToken())
.build());
// GitLab Runner that runs only tagged jobs
var taggedOnly = new Runner("taggedOnly", RunnerArgs.builder()
.registrationToken(myGroup.runnersToken())
.description("I only run tagged jobs")
.runUntagged("false")
.tagLists(
"tag_one",
"tag_two")
.build());
// GitLab Runner that only runs on protected branches
var protected_ = new Runner("protected", RunnerArgs.builder()
.registrationToken(myGroup.runnersToken())
.description("I only run protected jobs")
.accessLevel("ref_protected")
.build());
// Generate a `config.toml` file that you can use to create a runner
// This is the typical workflow for this resource, using it to create an authentication_token which can then be used
// to generate the `config.toml` file to prevent re-registering the runner every time new hardware is created.
var myCustomGroup = new Group("myCustomGroup", GroupArgs.builder()
.description("group that holds the custom runners")
.build());
var myRunner = new Runner("myRunner", RunnerArgs.builder()
.registrationToken(myCustomGroup.runnersToken())
.build());
// This creates a configuration for a local "shell" runner, but can be changed to generate whatever is needed.
// Place this configuration file on a server at `/etc/gitlab-runner/config.toml`, then run `gitlab-runner start`.
// See https://docs.gitlab.com/runner/configuration/advanced-configuration.html for more information.
var config = new File("config", FileArgs.builder()
.filename(String.format("%s/config.toml", path.module()))
.content(myRunner.authenticationToken().applyValue(authenticationToken -> """
concurrent = 1
[[runners]]
name = "Hello Terraform"
url = "https://example.gitlab.com/"
token = "%s"
executor = "shell"
", authenticationToken)))
.build());
}
}
resources:
# Basic GitLab Group Runner
myGroup:
type: gitlab:Group
properties:
description: group that holds the runners
basicRunner:
type: gitlab:Runner
properties:
registrationToken: ${myGroup.runnersToken}
# GitLab Runner that runs only tagged jobs
taggedOnly:
type: gitlab:Runner
properties:
registrationToken: ${myGroup.runnersToken}
description: I only run tagged jobs
runUntagged: 'false'
tagLists:
- tag_one
- tag_two
# GitLab Runner that only runs on protected branches
protected: # Generate a `config.toml` file that you can use to create a runner
# This is the typical workflow for this resource, using it to create an authentication_token which can then be used
# to generate the `config.toml` file to prevent re-registering the runner every time new hardware is created.
type: gitlab:Runner
properties:
registrationToken: ${myGroup.runnersToken}
description: I only run protected jobs
accessLevel: ref_protected
myCustomGroup:
type: gitlab:Group
properties:
description: group that holds the custom runners
myRunner:
type: gitlab:Runner
properties:
registrationToken: ${myCustomGroup.runnersToken}
# This creates a configuration for a local "shell" runner, but can be changed to generate whatever is needed.
# Place this configuration file on a server at `/etc/gitlab-runner/config.toml`, then run `gitlab-runner start`.
# See https://docs.gitlab.com/runner/configuration/advanced-configuration.html for more information.
config:
type: local:File
properties:
filename: ${path.module}/config.toml
content: " concurrent = 1\n\n [[runners]]\n name = \"Hello Terraform\"\n url = \"https://example.gitlab.com/\"\n token = \"${myRunner.authenticationToken}\"\n executor = \"shell\"\n \n"
Import
A GitLab Runner can be imported using the runner's ID, eg
$ pulumi import gitlab:index/runner:Runner this 1
Properties
The access_level of the runner. Valid values are: not_protected
, ref_protected
.
The authentication token used for building a config.toml file. This value is not present when imported.
The runner's description.
Maximum timeout set when this runner handles the job.
The registration token used to register the runner.
Whether the runner should handle untagged jobs.