Setting up a GitLab runner for MATLAB
Continuous Integration (CI) helps keep your code reliable by automatically building and testing changes. To run MATLAB inside a GitLab CI pipeline at TU Delft, you need your own GitLab runner.
This guide shows you how to:
- Set up a TU Delft VPS with a GitLab runner
- Build a custom Docker image with MATLAB
- Configure your TU Delft GitLab repository to run MATLAB jobs automatically
By following the steps, you’ll create a fully working CI pipeline capable of executing MATLAB code on each commit with the TU Delft GitLab. Some familiarity with Linux, GitLab, and Docker is helpful but not strictly required, the steps are designed to be followed sequentially and include all necessary commands.
Before you begin
Ensure you have the following ready:
Step 1. Request a TU Delft VPS
The TU Delft GitLab instance does not have runners available by default. To set up a runner for the repository, we need to deploy one on a separate (virtual) server in order to execute the jobs in the CI/CD pipeline. In order to accomodate the size of MATLAB, ensure to request 50Gb of disk space (the MATLAB installation in this guide requires ~10 Gb, but this depends on the size of the installed addons).
For additional information, please follow this guide to request a VPS.
Step 2. Set up a GitLab runner
To set up a GitLab runner on the VPS, please follow this guide for setting up GitLab runners.
In short, the steps are:
Install docker
sudo apt install docker.ioVerify installation
sudo docker --versionOptional: Move default storage location to larger drive
Deploy the gitlab-runner
sudo docker run -d --name gitlab-runner --restart always \ -v /srv/gitlab-runner/config:/etc/gitlab-runner \ -v /var/run/docker.sock:/var/run/docker.sock \ gitlab/gitlab-runner:latestVerify deployment with
sudo docker ps -a
Step 3. Create a Docker image containing a custom MATLAB installation
In order for a GitLab runner to execute MATLAB code, it needs to be able to access a container with MATLAB installed. The aim of this step is to create a Docker image with MATLAB installation that can be used by a GitLab runner. By building our own Docker image, we can specify the MATLAB version and customize the installed toolboxes.
The Dockerfile below is based on MATLAB’s MATLAB Dockerfile 2021. We will make the following (highlighted) modifications to this template:
- Update the MATLAB version to
r2025b. - Set
bashas the default run command (GitLab runners need to access a shell) - Add additional MATLAB products with the flag
--products. In this example, we have added theParallel Computing Toolboxand theMapping Toolbox.
In your user folder on the VPS (/home/username), create a file called
Dockerfilesudo nano DockerfileCopy the content below in the Dockerfile.
To build a Docker image with the name
matlab-gitlaband the version referencer2025b, run the following command in the folder containing the Dockerfile:sudo docker build . -t matlab-gitlab:r2025bYou can verify the presence of the image with
sudo docker imagesThis image is now available locally on the VPS.
Step 5. Create the GitLab runner
You can find the required gitlab-ci token in your GitLab repository under Settings -> CI/CD -> Runners.
- Press: Create project runner
- Add a tag for the runner:
matlab. This tag will be used to call this specific runner in the CI/CD configgitlab-ci.yml. - Press: Create runner
- Under Step 1, the runner authentication token is shown. You will need this token during the next step.
Register the MATLAB runner
After deploying the gitlab-runner in step 2, we need to register a new runner for our matlab-gitlab:r2025b image. Run the following command to register your runner and configure it to deploy in a Docker container on your server.
sudo docker run --rm -it -v /srv/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner register In response to this command you will be prompted to answer a series of questions:
- Enter the GitLab instance URL:
https://gitlab.tudelft.nl/ - Enter the registration token:
(from step 4) - Enter a name for the runner:
matlab-runner - Enter an executor:
docker - Enter the default Docker image:
matlab-gitlab:r2025b(name of the image created in step 3)
The runner configurations are stored in /srv/gitlab-runner/config/config.toml.
To finish the setup of the MATLAB runner, we need to modify the configuration file to add some additional Docker settings.
Open the configuration file with
sudo nano /srv/gitlab-runner/config/config.tomlupdate the following line
privileged = trueand add the following line under [runners.docker]:
pull_policy = "if-not-present"For the changes to take effect, restart the gitlab-runner with
sudo docker restart gitlab-runnerAfter registering the runner, the configuration file should contain:
config.toml
concurrent = 1
check_interval = 0
shutdown_timeout = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "matlab-gitlab"
url = "https://gitlab.tudelft.nl"
id = <runner id>
token = "<authentication token>"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.cache.azure]
[runners.docker]
tls_verify = false
image = "matlab-gitlab:r2025b"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
network_mtu = 0
pull_policy = "if-not-present"Step 6. Obtain a MATLAB license file
Every TU Delft employee has access to an Individual MATLAB license. Normally, you would activate MATLAB only once after installation through an online activation step. However, this does not work for a Docker container as it is relaunched for each CI trigger.
The following steps for activating MATLAB on an offline machine are adapted from the MATLAB Forum:
Obtain your Host ID The MATLAB license can only be activated for a specific computer. In the Docker container, we will set the hostID of the container to 0242ac11ffff.
Obtain your computer login name or username The MATLAB license is created for a specific user. In the Docker container, we will set the username to matlab.
Activate the license through the License Center to obtain license file
- Go to the License Center: https://www.mathworks.com/mwaccount
- Under My Software, click the license for Designated Computer
- Click the tab: Install and Activate
- Under related tasks, click Activate to Retrieve License File
- Enter the following information:
- the release you are activating = r2025b (same version as in the Dockerfile)
- the operating system = Linux
- the host ID = 0242ac11ffff
- the Computer Label = matlab-gitlab
- Select Continue
- Download the
license.licfile and save it to your local machine.
Step 7. Configure the CI/CD pipeline on GitLab
Before we can run a CI job, we need to configure the license in our GitLab repository. Having the license available as a GitLab variable allows us to renew it without having to change the MATLAB image.
Alternatively, we could have added the license file directly to the Docker image. With the license file in the same folder as the Dockerfile and adding the following command to the Dockerfile, we can build a Docker image with an activated MATLAB:
COPY license.lic /opt/matlab/licenses/Here, we opted to have it accessible through the GitLab settings together with the accompanying hostid.
Never share any Docker images that contain license files or other confidential information.
Under Settings -> CI/CD -> Variables, scroll down to Project variables and select Add variable.
- Type:
File - Environments:
All (default) - Visibility:
Visible(The license contains sensitive information, but its format is incompatible with themaskedsettings) - Key:
MATLAB_LICENSE - Value: Paste the content of the downloaded
license.licfile here
Step 8. Test the pipeline
To test the pipeline, add the following content to .gitlab-ci.yml via CI/CD -> Editor in your repository.
variables:
MAC_ADDRESS: 02:42:ac:11:ff:ff
check_matlab:
tags:
- matlab
# Optional : specify the docker image to use for this job if other than default in the runner config.toml
image: matlab-gitlab:r2025b
before_script:
# Change the mac-address to match the MATLAB license
- sudo ifconfig eth0 hw ether "$MAC_ADDRESS"
# Add the MATLAB license to the MATLAB installation in the container
- sudo mkdir /opt/matlab/licenses
- sudo mv ${MATLAB_LICENSE} /opt/matlab/licenses/license.lic
script:
# Run a MATLAB function/script through the -batch argument
- matlab -batch "disp('hello world!')"After committing, the pipeline should run and execute the job check_matlab. You can check the status of the pipeline via CI/CD -> Pipelines.
If all went well, you have successfully setup a GitLab runner to run MATLAB code. Congrats!
Step 9. (Optional) Update the MATLAB version
If you need to update the MATLAB version of the Docker container, you will need to go through the following steps:
- Update the MATLAB version in the Dockerfile
- Build the docker image with
sudo docker build . -t matlab-gitlab:<version> - Download a new
license.licfile for the new version (see step 5 of this guide) - Update the CI Variable
MATLAB_LICENSEwith the new license content - Update the image names (not the tags) in
.gitlab-ci.ymlto use the new image.