+44 (0) 121 212 9737 / team@substrakt.com
© 2018 Substrakt Registered in England. Company no. 5916054

How to: Debug GitLab CI Builds Locally

January 11, 2017

Your tests all pass locally. One test fails in your GitLab CI build. Sound familiar?

Of course it does.

This is painful work to resolve. You have to make single changes to your GitLab CI build file and push them to your origin one at a time until your builds pass or you give up and just live with the fact that only one test fails. Or you delete the test because you have no respect for the law.

But no more! You can now run individual test jobs using the gitlab-ci-multi-runner binary on your local machine exactly as GitLab CI runs them and be 100% sure that your tests will pass without having to commit tiny changes hundreds of times.

First of all, you need Docker installed on your machine. This should only take a few minutes.
Second, you need to install the gitlab-ci-multi-runner locally too. This is the exactly same application that runs the tests on the GitLab CI instance.

Then run the following command:

$ gitlab-ci-multi-runner exec docker {test_name}

That’s it. In my example Ruby project, my tests are run in a job called ‘test’, so replace {test_name} with test and it’ll run that on its own.

Screen Shot 2017-01-11 at 10.17.00

I’ve now got total confidence that these tests will pass during the GitLab CI run and it’s only taken me 10 minutes to fix rather than several hours.

Max Woolf