---
url: https://relizy.dev/guide/gitlab-ci.md
description: >-
  Release with GitLab CI - the job generated by relizy init, the relizy
  component of the CI/CD catalog, its CI/CD variables, the push access of the
  job, protected branches, canary releases on merge requests, and the outputs of
  the release.
---

# {{ $frontmatter.title }}

{{ $frontmatter.description }}

## The Generated Job

`npx relizy init` writes the release job in `.gitlab-ci.yml`, or in `.gitlab/ci/relizy.yml` when the project already has one, and prints the `include:` to add (see [release workflow](./../cli/init.md#release-workflow)). On gitlab.com, run on demand:

```yaml
# Generated by relizy init: https://relizy.dev/guide/gitlab-ci
# Add these masked CI/CD variables (Settings > CI/CD > Variables): GITLAB_TOKEN, NPM_TOKEN
# GITLAB_TOKEN: an access token with the api and write_repository scopes, to push the release commit and the tags

variables:
  RELEASE_TYPE:
    value: auto
    options: [auto, patch, minor, major]
    description: Release type (auto follows the commits)

include:
  # The release job, its outputs (RELIZY_RELEASED, RELIZY_VERSION, RELIZY_TAGS...) go to the next jobs: https://gitlab.com/relizy/relizy
  - component: gitlab.com/relizy/relizy/release@2
```

* **Release type**: choose it in the form of Build > Pipelines > Run pipeline (`RELEASE_TYPE`, `auto` passes no type flag: [`bump.type`](./../config/bump.md#type) of the config or of the profile applies, else the bump computed from the commits), or as a variable of the manual job before running it. With the push trigger, `init` gives `when: on_success` to the component, and no `RELEASE_TYPE`.
* **Rules**: only on the default branch, and never on the release commit pushed by Relizy (the `skip-commit` input follows your [`templates.commitMessage`](./../config/commit-templates.md)). The tag pipelines have no `CI_COMMIT_BRANCH`: the job does not run there either.
* **Stage**: `deploy` is a default stage of GitLab. When your `.gitlab-ci.yml` declares its own `stages:`, add `deploy` to them, or change the `stage` input.
* **Build**: `publish.buildCmd` builds the packages before publishing (set by `init` from your `build` script).

## The Relizy Component

The `release` component of the [CI/CD catalog](https://gitlab.com/explore/catalog) ([`gitlab.com/relizy/relizy`](https://gitlab.com/relizy/relizy)) adds the `release` job:

* **Image**: `node:lts`, or the Node version of `.nvmrc` or `.node-version` given by `init` (`image` input). Relizy needs Node `^22.23.4 || ^24.22.1 || >=26.12.1`.
* **Setup**: your package manager (from the lockfile: corepack for pnpm and Yarn, Bun, npm) and the install from the lockfile. `setup: false` skips it, when the image or a `before_script` already did.
* **npm**: updated to 11.5.1 or later for [trusted publishing](./trusted-publishing.md), with the `NPM_ID_TOKEN` id token.
* **AI rewrites**: the `claude` CLI, when `CLAUDE_CODE_OAUTH_TOKEN` is set.
* **Relizy**: the version of your `package.json`, else the version of the component (`relizy-version` forces one).
* **Release**: `relizy release --yes --report-dotenv relizy.env`, with the release type and the `args` you give, and the [outputs](#outputs-and-summary) as a `dotenv` artifact. `GIT_DEPTH: 0` only saves a fetch: Relizy fetches the history of a shallow clone, checks out the branch of the detached HEAD and sets the git identity itself (see [What Relizy Handles in CI](./ci-cd.md#what-relizy-handles-in-ci)).

```yaml
include:
  - component: gitlab.com/relizy/relizy/release@2
    inputs:
      when: on_success
      image: node:24
      args: --tag beta --preid beta
```

| Input               | Default                | Description                                                                                                              |
| ------------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `stage`             | `deploy`               | Stage of the job                                                                                                         |
| `image`             | `node:lts`             | Node.js image of the job                                                                                                 |
| `when`              | `manual`               | `manual` on demand, `on_success` at each push on the default branch                                                      |
| `release-type`      | `auto`                 | `auto`, `patch`, `minor`, `major`, `prerelease`... (`RELEASE_TYPE` takes precedence)                                     |
| `profile`           |                        | A [release profile](./../config/profiles.md) of the config (`beta`, `canary`...), as `--profile` (relizy 2.3.0 or later) |
| `args`              |                        | More arguments for `relizy release`: `--tag beta --preid beta`, `--dry-run`                                              |
| `skip-commit`       | `^chore\(release\): `  | Regular expression of the release commit, which does not run the job again                                               |
| `setup`             | `true`                 | Install the package manager and the dependencies                                                                         |
| `package-manager`   | from the lockfile      | `npm`, `pnpm`, `yarn` or `bun`                                                                                           |
| `relizy-version`    | the one of the project | Version of relizy, else the one of the component                                                                         |
| `working-directory` | `.`                    | Directory of the project                                                                                                 |

`@2` follows the latest relizy 2, `@2.3.0` stays on a version. The job is named `release`: a `release:` job of your `.gitlab-ci.yml` changes its other keys (`tags`, `cache`, `artifacts`...).

### A Self-Managed GitLab

A self-managed instance cannot include the components of gitlab.com: `init` writes the job itself, with the same steps. On gitlab.com, `init` writes it too when you choose the relizy CLI (`How does the CI run relizy?`) (mirror the project [`gitlab.com/relizy/relizy`](https://gitlab.com/relizy/relizy) on your instance to include the component instead):

```yaml
release:
  stage: deploy
  image: node:lts
  variables:
    # The changelogs need the history since the last release
    GIT_DEPTH: 0
  # npm trusted publishing (OIDC): publishes without NPM_TOKEN once set up on npmjs.com
  id_tokens:
    NPM_ID_TOKEN:
      aud: npm:registry.npmjs.org
  rules:
    # On the default branch, not on the release commit it pushes
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE !~ /^chore\(release\): /'
      when: manual
  before_script:
    - npm install -g corepack && corepack enable
    - pnpm install --frozen-lockfile
    # npm trusted publishing (OIDC) needs npm 11.5.1 or later: https://relizy.dev/guide/trusted-publishing
    - npm install -g npm@latest
  script:
    - if [ "$RELEASE_TYPE" != "auto" ]; then RELEASE_FLAG="--$RELEASE_TYPE"; fi
    - pnpm exec relizy release --yes $RELEASE_FLAG --report-dotenv relizy.env
  artifacts:
    # The outputs of the release (RELIZY_RELEASED, RELIZY_VERSION, RELIZY_TAGS...), for the next jobs
    reports:
      dotenv: relizy.env
```

pnpm and yarn come from corepack (`npm install -g corepack && corepack enable`: Node 25+ no longer ships it), bun from `npm install -g bun`. With AI rewrites, the job installs the `claude` CLI: `npm install -g @anthropic-ai/claude-code`.

## CI/CD Variables

Add them in Settings > CI/CD > Variables, masked. GitLab passes them to the job under the same names.

| Variable                                                                                           | When                                                                     |
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| `GITLAB_TOKEN`                                                                                     | Always: push, GitLab release, MR comment                                 |
| `NPM_TOKEN`                                                                                        | Publishing to npm, without [trusted publishing](./trusted-publishing.md) |
| `TWITTER_API_KEY`, `TWITTER_API_KEY_SECRET`, `TWITTER_ACCESS_TOKEN`, `TWITTER_ACCESS_TOKEN_SECRET` | [Twitter posts](./social-media.md)                                       |
| `SLACK_TOKEN`                                                                                      | [Slack posts](./social-media.md)                                         |
| `TEAMS_WEBHOOK_URL_B64` (the URL in base64: a masked variable refuses its characters)              | [Teams cards](./social-media.md#microsoft-teams)                         |
| `CLAUDE_CODE_OAUTH_TOKEN`                                                                          | [AI rewrites](./ai-changelog.md)                                         |

All the variables and their aliases: [Tokens](./../config/overview.md#tokens). Relizy writes the npm token to a temporary `.npmrc` itself: no `.npmrc` to write in the job.

`GITLAB_TOKEN` is an access token with the `api` and `write_repository` scopes, and a role allowed to push to the default branch (Maintainer by default): a project access token (Settings > Access tokens), or on the Free tier of gitlab.com, where project access tokens need Premium, a personal access token (of a bot account, ideally). To push without a token, allow the job token to push (see [Push Access](#push-access)). The job token (`CI_JOB_TOKEN`) creates the GitLab releases, but cannot comment the merge requests: the MR comment needs `GITLAB_TOKEN`.

A protected variable is only given to the pipelines of protected branches and tags: leave `NPM_TOKEN` and `GITLAB_TOKEN` unprotected for the [canary releases](#canary-release-on-merge-requests) of merge requests.

## Push Access

GitLab checks out the commit with the job token, which cannot push by default. Before publishing, Relizy checks the push, and pushes through `GITLAB_TOKEN` when the job token cannot. Without a token able to push, the release stops before publishing:

```text
relizy cannot push the release commit and tags to "origin" from GitLab CI: the job token cannot push.
Fix: add a GITLAB_TOKEN CI/CD variable (an access token with the "write_repository" and "api" scopes), or allow the job token to push in Settings > CI/CD > Job token permissions.
```

When `GITLAB_TOKEN` is set but cannot push either (expired, without the `write_repository` scope, or a role that cannot push), the error says so: check the token, not the job token.

Instead of pushing with `GITLAB_TOKEN`, you can allow the job token to push (Settings > CI/CD > Job token permissions, Allow Git push requests to the repository): its push starts no pipeline. A push with `GITLAB_TOKEN` starts the pipelines of the release commit and of the tags, which the rules of the `release` job skip.

The release commit and the tags are made by the person who started the pipeline (or the manual job), with their noreply email (`42-jdoe@users.noreply.gitlab.com`), not by the user of the token.

## Protected Branches and Tags

The push access check does not apply the rules of protected branches: a branch the role of the token cannot push to rejects the release commit, after the publish. In Settings > Repository:

* **Protected branches**: allow the role of `GITLAB_TOKEN` (or the bot user of the token) to push to the default branch.
* **Protected tags**: when the release tags (`v*`) are protected, allow this role to create them.

## Outputs and Summary

`--report-dotenv relizy.env` writes the outputs of the [report](./../config/release.md#report) (`RELIZY_RELEASED`, `RELIZY_STATUS`, `RELIZY_VERSION`, `RELIZY_TAGS`, `RELIZY_PACKAGES`, `RELIZY_URLS`...), and the `dotenv` artifact gives them to the next jobs:

```yaml
deploy-docs:
  stage: deploy
  needs: [release]
  # The rules of the release job: a job cannot need a job missing from the pipeline
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE !~ /^chore\(release\): /'
  script:
    - |
      if [ "$RELIZY_RELEASED" = "true" ]; then
        ./scripts/deploy-docs.sh "$RELIZY_VERSION"
      else
        echo "Nothing released"
      fi
```

In a monorepo, `RELIZY_PACKAGE_<NAME>_VERSION` (`@acme/ui` gives `RELIZY_PACKAGE_ACME_UI_VERSION`) and `RELIZY_GROUP_<NAME>_VERSION` are only set for what was released, to run something for one package only:

```yaml
notify-ui:
  stage: deploy
  needs: [release]
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_COMMIT_MESSAGE !~ /^chore\(release\): /'
  script:
    - |
      if [ -n "$RELIZY_PACKAGE_ACME_UI_VERSION" ]; then
        ./scripts/notify.sh "@acme/ui $RELIZY_PACKAGE_ACME_UI_VERSION" || echo "Notification failed"
      fi
```

GitLab CI has no summary of the run: write it to a markdown file and expose it as an artifact of the merge request, or read it in the [MR comment](./pr-comment.md).

```yaml
include:
  - component: gitlab.com/relizy/relizy/release@2
    inputs:
      args: --report-markdown relizy-summary.md

release:
  artifacts:
    expose_as: Release summary
    paths: [relizy-summary.md]
    reports:
      dotenv: relizy.env
```

## Variants

### Dry Run

`args: --dry-run` (or `pnpm exec relizy release --yes --dry-run`) previews the release in any job: nothing is written, committed nor published, and `RELIZY_RELEASED` is `false`.

### Preview the Release on Merge Requests

The `merge-preview` component adds a job to the merge request pipelines into the default branch, which runs [`relizy merge-preview`](./../cli/merge-preview.md): a comment tells what the merge releases, and the job fails when the release of the merge would fail. Nothing is written nor published. `relizy init` offers it, `relizy merge-preview init` adds it to a project already set up; see [Merge Preview](./merge-preview.md).

```yaml
include:
  - component: gitlab.com/relizy/relizy/release@2
  - component: gitlab.com/relizy/relizy/merge-preview@2
```

### Lint the Commits of Merge Requests

The `commitlint` component adds a `commitlint` job to the merge request pipelines, which runs [`relizy commitlint`](./../commitlint/cli.md) on the commits of the merge request, with your config: the job fails on a commit the release would misread. The title of the merge request is linted too, from the merge method (see [`commitlint.title`](./../commitlint/config.md#title)): `args: --title` lints it as errors whatever the merge. See [Commitlint](./../commitlint/index.md#lint-the-commits-of-a-pull-request).

```yaml
include:
  - component: gitlab.com/relizy/relizy/commitlint@2
```

Its inputs: `stage` (`test`), `image`, `args`, `setup`, `package-manager`, `relizy-version` and `working-directory`, as the ones of `release`.

### Canary Release on Merge Requests

Publish a test version of each merge request (`1.3.0-0.canary-a3f4b2c` on the `canary` dist-tag), and comment it on the merge request. Nothing is committed nor pushed (see [Canary Releases](./prereleases.md#canary-releases)). The component only releases the default branch: the canary job is written out.

```yaml
canary:
  stage: deploy
  image: node:lts
  variables:
    GIT_DEPTH: 0
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
  before_script:
    - npm install -g corepack && corepack enable
    - pnpm install --frozen-lockfile
  script:
    # The number also covers the merged results pipelines, whose commit belongs to no merge request
    - pnpm exec relizy release --canary --yes --pr-number $CI_MERGE_REQUEST_IID
```

The merge requests of forks run in the pipelines of the fork, without the variables of your project: they get no canary.

### Merge the Release into develop

With a git flow, add the rule `sync: { rules: [{ from: 'main', to: ['develop'] }] }`: the release job of `main` merges it into `develop` once pushed, with `GITLAB_TOKEN` when the job token cannot push. No job of your own: see [Branch Sync](./branch-sync.md).
