Here, we'll walk through a tutorial to start using CML on GitLab.
Fork our example project repository. Click on Fork and select the namespace where you would like to keep the project.
⚠️ In GitLab, to use CML, you must create a variable called a
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
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 Settings ➡ CI/CD ➡ Varibles.
f. Scroll to Variables and expand the field. Click "Add Variable". In the Key
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.
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
<user_name> with your own from GitLab.
git clone https://gitlab.com/<user_name>/example_cml.git
Change directory to
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
train.pyand edit line 16 to
depth = 5.
Commit and push the changes using:
git checkout -b experiment git add . && git commit -m "modify forest depth" git push origin experiment
Go back to GitLab in a Browser window and create a merge request.
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
⚠️ Change target branch to your local branch with your username.
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.