# Run your GitLab CI jobs on LiveTerminal

:::caution[Preview: turned on per team]
LiveTerminal CI is in preview and turned on only for some teams. For any other team, connecting
answers `ci_not_enabled` and the dashboard's CI page says CI isn't turned on yet. To run CI on
LiveTerminal today without it, install a runner on a VPS:
[Run your CI runner on a LiveTerminal VPS](/ci-runner/).
:::

You keep your pipelines in `.gitlab-ci.yml`, as they are. You connect a GitLab project once, add a
size tag to a job, and push. GitLab sends that job to LiveTerminal, which runs it in a fresh
machine of that size, used for that one job and then deleted. You don't run a runner or a VPS for
it.

## Sizes

A job picks its machine with a tag:

| Tag     | vCPUs | RAM    |
| ------- | ----- | ------ |
| `lt-2`  | 2     | 4 GiB  |
| `lt-4`  | 4     | 8 GiB  |
| `lt-8`  | 8     | 16 GiB |
| `lt-16` | 16    | 32 GiB |

## Before you start

- A project on GitLab.com where you are a Maintainer or Owner. LiveTerminal connects GitLab.com
  only.
- The write or owner role in your LiveTerminal team.
- CI turned on for your team (see the note above).

## 1. Make a GitLab access token

In GitLab, open your **Personal access tokens** page
(<https://gitlab.com/-/user_settings/personal_access_tokens>) and add a token with these scopes:

- `create_runner`: LiveTerminal adds a runner to your project for each size.
- `manage_runner`: LiveTerminal deletes those runners again when you disconnect.
- `read_api`: LiveTerminal looks up the project you name.

LiveTerminal keeps the token encrypted, and uses it only for these runners.

## 2. Connect the project

In a terminal, with the token in a variable or a file:

```sh
printf %s "$GITLAB_TOKEN" | lt ci connect gitlab --token - --project mygroup/myapp
```

```text
Connected mygroup/myapp (gitlab.com) as cic_7Kq2mZ9xLp. Runners: lt-2 lt-4 lt-8 lt-16.
Next: add `tags: [lt-2]` to a job in .gitlab-ci.yml and push. See jobs with: lt ci jobs
```

- `--token -` reads the token from a pipe or a file, never from the terminal (which would show it),
  so it stays out of your shell history. `lt` never prints it.
- `--project` takes the path or GitLab's numeric project ID.
- `--labels lt-2,lt-4` connects only some sizes; the default is all four.

In the dashboard, the same is **CI** in the sidebar, then **Connect GitLab**.

In GitLab, the project's **Settings > CI/CD > Runners** now lists one LiveTerminal runner per size.

If GitLab refuses the token, `lt` shows GitLab's reason, for example a missing scope.

**With a runner token instead.** Create a runner yourself in GitLab (**Settings > CI/CD > Runners >
New project runner**) with one size tag, such as `lt-4`, and copy its token (`glrt-…`):

```sh
lt ci connect gitlab --token - --label lt-4 < runner-token.txt
```

GitLab then lists a runner manager named `s_ltconnectcheck` on that runner: that is LiveTerminal's
check of the token.

## 3. Tag a job and push

Add the tag to a job you already have, or try this one-job `.gitlab-ci.yml`:

```yaml
test:
  tags: [lt-4]
  image: node:22
  script:
    - node --version
```

Push, and GitLab runs the job on LiveTerminal. Jobs without an `lt-` tag keep running where they
ran before.

## 4. See your jobs

```sh
lt ci jobs        # ID, PROJECT, JOB, SIZE, STATE, WAITED, RAN, WHEN
```

- JOB is GitLab's job number. STATE is `running`, then `succeeded`, `failed` or `canceled`.
  WAITED is the seconds from LiveTerminal receiving the job to the job starting, and RAN is the
  seconds it ran.
- Filter with `--state running|succeeded|failed|canceled` and `--project mygroup/myapp`.
- Add `--json` for the full records. Each job's `webUrl` opens its page and log in GitLab.
- The log, retries and cancelling stay in GitLab.

In the dashboard, the **CI** page lists the same jobs; a job's number opens it in GitLab.

## What a job runs in

- A job's `image:` runs as a container in the job's machine. Public images (Docker Hub, ghcr.io,
  quay.io, registry.gitlab.com) come through a mirror on the CI server that all its jobs share,
  so Docker Hub's pull limits can show up as a failed pull.
- A job's container is not privileged and has no Docker socket: `docker build` and `docker:dind`
  don't work in a job. Build images on your VPS and push them to your
  [container registry](/container-images/).
- Pulling an image from your LiveTerminal container registry in a job isn't available yet.

## Cache

GitLab's `cache:` works. The jobs of one connection share a cache, across sizes: a job on `lt-2`
can save a cache that a later job on `lt-4` restores. Treat it as a cache: an entry can be gone,
and the job must still pass without it.

## More projects

Connect each project on its own; each connection gets its own runners. Connecting the same
project twice makes a second set of runners, so disconnect the old connection first.

```sh
lt ci connections   # ID, CONNECTED (the project path), KIND, SIZES, SINCE, ...
```

## Disconnect

```sh
lt ci disconnect cic_7Kq2mZ9xLp
```

LiveTerminal deletes the runners it created in GitLab, then stops running the connection's jobs.
Jobs tagged `lt-2` … `lt-16` then wait in GitLab unless another runner has those tags. A runner you
created yourself with a runner token stays in GitLab: delete it there. In the dashboard, it's
**Disconnect** in the connection's menu.

If GitLab refuses or fails, nothing changes on the LiveTerminal side: try again, or delete the
runners in GitLab.