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.

  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.

    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/CDVaribles.

    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.

    git clone https://gitlab.com/<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.

    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
  4. In your text editor, open train.py 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.

  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.

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

  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 function cml-send-comment in your workflow.

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

Edit on GitHub

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

Discord Chat

    About

  • Install
  • Use cases
  • Blog
  • Github

By iterative.ai - An open platform to operationalize AI