> ## Documentation Index
> Fetch the complete documentation index at: https://www.qovery.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# GitLab CI

> Deploy with GitLab CI and Qovery CLI

Deploy your applications with GitLab CI using the Qovery CLI.

## Prerequisites

Before you can deploy your application with GitLab CI, you need to:

1. Install the [Qovery CLI](/cli/overview)
2. Generate a [Qovery API token](/configuration/organization/api-token) (via CLI or Console)
3. Set the environment variable `QOVERY_CLI_ACCESS_TOKEN` with your API token
4. Disable [Qovery Auto Deployment](/configuration/deployment/auto-deploy) on the services you want to deploy manually

## Deploy a Container Application

Here is an example of a GitLab CI configuration file (`.gitlab-ci.yml`) to deploy a container application:

```yaml theme={null}
stages:
  - build
  - deploy

build:
  stage: build
  image: docker:latest
  services:
    - docker:dind
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA .
    - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA

deploy:
  stage: deploy
  image: alpine:latest
  script:
    - apk add --no-cache curl bash
    - curl -s https://get.qovery.com | bash
    - export QOVERY_CLI_ACCESS_TOKEN=$QOVERY_CLI_ACCESS_TOKEN
    - qovery container deploy \
        --organization "My Organization" \
        --project "My Project" \
        --environment "Production" \
        --container "myapp" \
        --tag $CI_COMMIT_SHA \
        --watch
  only:
    - main
```

This workflow assumes you have:

* A container registry connected to Qovery
* An existing container application on Qovery
* Set the `QOVERY_CLI_ACCESS_TOKEN` variable in your GitLab CI/CD settings

## Deploy a Single Application

Use the Qovery CLI to deploy a single application:

```bash theme={null}
qovery application deploy \
  --organization "My Organization" \
  --project "My Project" \
  --environment "Production" \
  --application "myapp" \
  --commit-id <commit-id> \
  --watch
```

## Deploy Multiple Applications

### Different Applications with Different Commits

```bash theme={null}
qovery application deploy \
  --organization "My Organization" \
  --project "My Project" \
  --environment "Production" \
  --application "app1" \
  --commit-id <commit-id-1> \
  --watch

qovery application deploy \
  --organization "My Organization" \
  --project "My Project" \
  --environment "Production" \
  --application "app2" \
  --commit-id <commit-id-2> \
  --watch
```

### Multiple Applications with the Same Commit (Monorepo)

```bash theme={null}
qovery application deploy \
  --organization "My Organization" \
  --project "My Project" \
  --environment "Production" \
  --applications "app1,app2,app3" \
  --commit-id <commit-id> \
  --watch
```

## Manage Preview Environments

### Clone an Environment

```bash theme={null}
qovery environment clone \
  --organization "My Organization" \
  --project "My Project" \
  --environment "Production" \
  --new-environment-name "preview-mr-123" \
  --cluster "my-cluster"
```

### Update Application Branch in Cloned Environment

```bash theme={null}
qovery application update \
  --organization "My Organization" \
  --project "My Project" \
  --environment "preview-mr-123" \
  --application "myapp" \
  --branch "feature-branch"
```

### Deploy the Preview Environment

```bash theme={null}
qovery application deploy \
  --organization "My Organization" \
  --project "My Project" \
  --environment "preview-mr-123" \
  --application "myapp" \
  --commit-id <commit-id> \
  --watch
```

### Delete Preview Environment

```bash theme={null}
qovery environment delete \
  --organization "My Organization" \
  --project "My Project" \
  --environment "preview-mr-123" \
  --yes
```

## Integration with Terraform

If you're using Terraform to manage your infrastructure, you can integrate it with your CI/CD pipeline. See the [Terraform Provider documentation](/using-qovery/interface/terraform-provider) for more information.

## Next Steps

<CardGroup cols={2}>
  <Card title="Qovery CLI" icon="terminal" href="/cli/overview">
    Learn more about Qovery CLI commands
  </Card>

  <Card title="API Token" icon="key" href="/configuration/organization/api-token">
    Generate and manage API tokens
  </Card>

  <Card title="Auto-Deploy" icon="rotate" href="/configuration/deployment/auto-deploy">
    Configure automatic deployments
  </Card>

  <Card title="GitHub Actions" icon="https://mintcdn.com/qovery/Nvnl0g5BHzA0XQmy/images/logos/github-icon.svg?fit=max&auto=format&n=Nvnl0g5BHzA0XQmy&q=85&s=8bd221fee047ba947afcfd39bd14ef08" href="/configuration/integrations/ci-cd/github-actions" width="24" height="24" data-path="images/logos/github-icon.svg">
    Deploy with GitHub Actions
  </Card>
</CardGroup>
