Skip to content
Casper da Costa-Luis edited this page Jun 16, 2021 · 2 revisions

CML is designed to work with both GitHub Actions and GitLab CI. Here, we'll discuss setting up CML with GitLab.

CML allows you to generate visual reports about your workflow on Merge Requests:

The key file in any GitLab CI project is .gitlab-ci.yml. For example, to generate the report pictured above, your .gitlab-ci.yml file should look like this:

# .gitlab-ci.yml
stages: 
    - cml_run
    
cml:
    stage: cml_run
    image: dvcorg/cml-py3:latest
    
    script:
        - pip3 install -r requirements.txt
        - python train.py
          
        - cat metrics.txt >> report.md
        - cml-publish confusion_matrix.png --md >> report.md
        - cml-send-comment report.md     

CML in GitLab works exactly as in GitHub except for a few conventions:

Variables

To use CML, you must create a variable called repo_token whose value is a Personal Access Token:

  1. Create a Personal Access Token by navigating to User SettingsAccess Tokens.

  2. In the "Name" field, type "repo_token" and check boxes to select "api", "read_repository" and "write_repository". Then click "Create personal access token".

  3. Copy the generated Personal Access Token.

  4. In your GitLab project, navigate to SettingsCI/CDVariables.

  5. Click "Add Variable". In the Key field, type "repo_token". In the Value field, paste your Personal Access Token. Check the "Mask variable" box, uncheck "Protect variable", and then save the variable by clicking "Add variable" at the bottom of the dialog box.

Tada, 🎩✨ repo_token is saved! You can follow this procedure (specifically, steps 4 & 5) for adding other secrets, like access credentials for cloud storage,

Using CML with DVC

Please see the example on our README, noting one difference: repository credentials are still required, but are entered as Variables instead of Secrets.

Using self-hosted runners

Follow GitLab's instructions to set up a runner manually or with a Kubernetes cluster.

A library of sample projects