# Automate Project Management with Rudder CLI and GitLab CI/CD


This guide shows how to run the same **validate** and **apply** workflow you use locally inside a GitLab pipeline.

## Prerequisites

- A GitLab project with your Rudder CLI YAML project checked in
- A [workspace-level Service Access Token]({{< ref "access-management/service-access-tokens.md#workspace-sat" >}}) with permissions for the resources you manage (see [Import Workspace Resources]({{< ref "dev-tools/rudder-cli/import-resources/" >}}) for a full permission matrix)
- **If you're on Free or self-hosted plan, or for testing and development only**: A [Personal Access Token]({{< ref "access-management/personal-access-tokens.md" >}}) with **Read-Write** role — see [Import Workspace Resources]({{< ref "dev-tools/rudder-cli/import-resources/" >}}#required-permissions) for token types and caveats
- Store the token as a masked [CI/CD variable](https://docs.gitlab.com/ee/ci/variables/) (for example `RUDDERSTACK_ACCESS_TOKEN`)

## Example pipeline

The following `.gitlab-ci.yml` sketches a two-stage flow: validate on every branch, apply only on the default branch after validation succeeds. Adjust image, paths, and branch rules to match your environment.

```yaml
stages:
  - validate
  - apply

variables:
  RUDDER_PROJECT_PATH: "$CI_PROJECT_DIR/my-rudder-project"

validate:
  stage: validate
  image: rudderlabs/rudder-cli
  script:
    - rudder-cli validate -l "$RUDDER_PROJECT_PATH"
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH

apply:
  stage: apply
  image: rudderlabs/rudder-cli
  script:
    - rudder-cli apply -l "$RUDDER_PROJECT_PATH" --dry-run
    - rudder-cli apply -l "$RUDDER_PROJECT_PATH"
  rules:
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  needs: ["validate"]
```

{{< info >}}
Use the official CLI image only if it matches the version you run locally. Alternatively install the binary in the job (for example from GitHub releases) so versions stay aligned with [Install Rudder CLI]({{< ref "dev-tools/rudder-cli/installation.md" >}}).
{{< /info >}}

## See more

- [GitHub Actions for Rudder CLI]({{< ref "dev-tools/rudder-cli/github-actions/" >}}) for the maintained GitHub Action and workflow patterns
- [Commands Reference]({{< ref "dev-tools/rudder-cli/commands.md" >}}) for core `rudder-cli` commands and subcommands

