Get started
Edit on GitHub

Using CML on GitLab

Here, we'll walk through a tutorial to start using CML on GitLab.

  1. Fork our example project repository. Click on Fork and select the namespace where you would like to keep the project.

    gitlab fork cml project

  2. ⚠️ In GitLab, to use CML, you must create a variable called a REPO_TOKEN whose value is a Personal Access Token. To do this:

    a. Click on your Avatar in the upper right side and click on "Edit Profile."

    b. Along the left side of the screen go to Access Tokens.

    c. In the "Name" field, type REPO_TOKEN and check boxes to select api, read_repository and write_repository.

    d. Click on the "Create personal access token" button and copy the generated access token.

    personal access token

    e. Head back to your fork by clicking the Projects tab next to the GitLab logo and select it.

    f. On the left hand side Navigate to SettingsCI/CDVariables.

    ci cd navigation

    f. Scroll to Variables and expand the field. 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.

💡 The following steps can all be done in the GitLab website. However, to follow along the steps, we recommend cloning your fork to your local workstation.

  1. Go back to your forked example_cml project. Copy the Clone with HTTPS as shown in the image below, and then in your terminal, type the following command, replacing <user_name> with your own from GitLab.

    gitlab cml clone

    $ git clone<user_name>/example_cml.git
  2. Change directory to example_cml.

    $ cd example_cml
  3. To create a CML workflow, use your editor of choice to copy the following into a new file .gitlab-ci.yml and save.

      image: iterativeai/cml:0-dvc2-base1
        - pip install -r requirements.txt
        - python
        - cat metrics.txt >>
        - cml publish plot.png --md >>
        - cml send-comment
  4. In your text editor, open and edit line 16 to depth = 5.

  5. Commit and push the changes using:

    $ git checkout -b experiment
    $ git add . && git commit -m "modify forest depth"
    $ git push origin experiment
  6. Go back to GitLab in a Browser window and create a merge request.

    create merge request

  7. If you arrive at a New Merge Request screen that says it's merging into anything other than your local repository, click on Change branches seen here.

    new merge request

  8. ⚠️ Change target branch to your local branch with your username.

    change user name

  9. Click on the "Compare branches and continue" button. Enter any additional comments you would like to put in the description and click the "Submit merge request" button. Shortly, you should see a comment from GitLab CI appear in the Pull Request with your CML report. This is a result of the cml send-comment command in your workflow.

    cml start gitlab end

Final Solution

An example of what your repository should look like now can be found at


🐛 Found an issue? Let us know! Or fix it:

Edit on GitHub

Have a question? Join our chat, we will help you:

Discord Chat