> ## Documentation Index
> Fetch the complete documentation index at: https://arize-ax.mintlify.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Gitlab CI/CD Basics

> GitLab CI/CD allows you to automate workflows directly from your GitLab repository. It enables you to build, test, and deploy your code based on specific events (such as code pushes, merge requests)

# **Key Concepts of GitLab CI/CD**

* **Pipelines**: Automated processes that you define in your repository.
* **Stages**: Groups of jobs that run sequentially (e.g., build, test, deploy).
* **Jobs**: Tasks that run in parallel within a stage.
* **Scripts**: Commands that run in the job's environment.
* **Runners**: Servers that execute the jobs in your pipeline.

# Adding a GitLab CI/CD Pipeline to Your Repository

## **Create a `.gitlab-ci.yml` File:**

* Create a `.gitlab-ci.yml` file in the root directory of your repository.
* Use YAML syntax to define your pipeline.

```yaml theme={null}
stages:
  - test

variables:
  # These variables need to be defined in GitLab CI/CD settings
  # The $ syntax is how GitLab references variables
  OPENAI_API_KEY: $OPENAI_API_KEY
  ARIZE_API_KEY: $ARIZE_API_KEY
  SPACE_ID: $SPACE_ID
  DATASET_ID: $DATASET_ID

llm-experiment-job:
  stage: test
  image: python:3.10
  # The 'only' directive specifies when this job should run
  # This will run for merge requests that change files in copilot/search
  only:
    refs:
      - merge_requests
    changes:
      - copilot/search/**/*
  script:
    - pip install -q arize==7.36.0 arize-phoenix==4.29.0 nest_asyncio packaging openai 'gql[all]'
    - python ./copilot/experiments/ai_search_test.py
  artifacts:
    paths:
      - experiment_results.json
    expire_in: 1 week
```

**Breakdown:**

* `stages`: The stages that will run as part of the pipeline.
* `variables`: Environment variables for your pipeline.
* `llm-experiment-job`: The name of the job that will run.
* `stage`: Specifies which stage the job belongs to.
* `image`: The Docker image to use for the job.
* `only`: Conditions that determine when the job will run.
* `script`: Commands to run in the job.
* `artifacts`: Files to save after the job completes.

### Common `only` Event Options:

1. **Merge Requests**: Triggers the pipeline when a merge request is created or updated.

```yaml theme={null}
only:
  - merge_requests
```

2. **Specific Branches**: Triggers the pipeline when code is pushed to specific branches.

```yaml theme={null}
only:
  - main
  - develop
```

3. **Changes to Specific Files**: Triggers the pipeline when specific files are changed.

```yaml theme={null}
only:
  changes:
    - copilot/search/**/*
```

4. **Scheduled Pipelines**: Triggers the pipeline on a scheduled time.

```yaml theme={null}
only:
  - schedules
```

5. **Tags**: Triggers the pipeline when a tag is created.

```yaml theme={null}
only:
  - tags
```

6. **Combining Multiple Conditions**: You can combine multiple conditions for more granular control.

```yaml theme={null}
only:
  refs:
    - merge_requests
    - main
  changes:
    - copilot/search/**/*
```
