Custom GitLab Runner driver that provisions CI jobs in Vagrant VMs (currently Windows and macOS guest boxes) using the runner custom executor lifecycle.
On macOS, you can use homebrew with a custom gitlab-vagrant-driver tap:
brew install nicerloop/gitlab-vagrant-driver/gitlab-vagrant-driverWhen registering a GitLab Runner for this driver, choose the custom executor, install the driver script in a directory on PATH, then configure the custom stage commands to call gitlab-vagrant-driver.
Example install:
install -m 0755 ./bin/gitlab-vagrant-driver /usr/local/bin/gitlab-vagrant-driverExample config.toml section for a registered runner:
[[runners]]
name = "vagrant-custom-runner"
executor = "custom"
[runners.custom]
config_exec = "gitlab-vagrant-driver"
config_args = ["config", "image=bento/windows-11", "provider=virtualbox", "template=share/templates/Vagrantfile.vbox.win.erb"]
prepare_exec = "gitlab-vagrant-driver"
prepare_args = ["prepare"]
run_exec = "gitlab-vagrant-driver"
run_args = ["run"]
cleanup_exec = "gitlab-vagrant-driver"
cleanup_args = ["cleanup"]Ensure the runner service account can resolve gitlab-vagrant-driver from PATH.
The driver script is at bin/gitlab-vagrant-driver and supports four stages:
config: returns driver + job environment metadata in JSONprepare: creates aVagrantfileand boots the VMrun: uploads and executes the job script in the guestcleanup: destroys the VM
bin/gitlab-vagrant-driver <stage> [args...]bin/gitlab-vagrant-driver config image=bento/windows-11 provider=virtualbox template=share/templates/Vagrantfile.vbox.win.erbAccepted args:
image=<box-name[:version]>provider=<vagrant-provider>template=<path-to-vagrantfile-template>
Notes:
CUSTOM_ENV_JOB_IMAGEoverrides theimagevalue when present.- Supported guests are inferred from image/box name:
- names containing
windowsusepowershell+winrm - names containing
macosusesh+ssh
- names containing
bin/gitlab-vagrant-driver prepareRuns:
vagrant init ... --forcevagrant up ...
bin/gitlab-vagrant-driver run ./job_script.ps1 "optional description"Behavior:
- uploads script to guest temp dir
- executes through the selected communicator (
winrmorssh)
bin/gitlab-vagrant-driver cleanupDestroys VM with force.
Enable shell tracing and emit driver.env during config:
export VAGRANT_DRIVER_DEBUG=1Built-in templates:
share/templates/Vagrantfile.erbshare/templates/Vagrantfile.tart.mac.erbshare/templates/Vagrantfile.vbox.win.erbshare/templates/gitlab-runner-config-template.toml
Under test/:
start.sh: boots local GitLab, registers runner, creates sample project/pipelinestop.sh: tears down local test environmentbuild-bento.sh: builds and adds localbento/windows-11box
Run from repo root:
cd test
./start.sh
# ... validate pipeline execution ...
./stop.sh