{"id":1786,"date":"2021-01-27T20:59:40","date_gmt":"2021-01-27T20:59:40","guid":{"rendered":"https:\/\/jan.schnasse.org\/blog\/?p=1786"},"modified":"2026-09-28T11:38:03","modified_gmt":"2026-09-28T09:38:03","slug":"run-gitlab-ci-locally","status":"publish","type":"post","link":"https:\/\/jan.schnasse.org\/blog\/2021\/01\/27\/run-gitlab-ci-locally\/","title":{"rendered":"Run Gitlab CI locally"},"content":{"rendered":"<div class=\"s-prose js-post-body\">\n<div class=\"s-prose js-post-body\">\n<p>I use this docker-based approach.<\/p>\n<p><strong>0. Create a git repo to test this<br \/>\n<\/strong><\/p>\n<pre class=\"lang-yaml s-code-block hljs\"><code><span class=\"hljs-string\">mkdir<\/span> <span class=\"hljs-string\">my-git-project<\/span>\n<span class=\"hljs-string\">cd<\/span> <span class=\"hljs-string\">my-git-project<\/span>\n<span class=\"hljs-string\">git<\/span> <span class=\"hljs-string\">init<\/span>\n<span class=\"hljs-string\">git<\/span> <span class=\"hljs-string\">commit<\/span> <span class=\"hljs-string\">--allow-empty<\/span> <span class=\"hljs-string\">-m\"Initialize<\/span> <span class=\"hljs-string\">repo<\/span> <span class=\"hljs-string\">to<\/span> <span class=\"hljs-string\">showcase<\/span> <span class=\"hljs-string\">gitlab-runner<\/span> <span class=\"hljs-string\">locally.\"<\/span>\n<\/code><\/pre>\n<p><strong>1. Go to your git directory<\/strong><\/p>\n<pre class=\"lang-yaml s-code-block hljs\"><code><span class=\"hljs-string\">cd<\/span> <span class=\"hljs-string\">my-git-project<\/span>\n<\/code><\/pre>\n<p><strong>2. Create a .gitlab-ci.yml<\/strong><\/p>\n<p>Example <code>.gitlab-ci.yml<\/code><\/p>\n<pre class=\"lang-yaml s-code-block hljs\"><code><span class=\"hljs-attr\">image:<\/span> <span class=\"hljs-string\">alpine<\/span>\n\n<span class=\"hljs-attr\">test:<\/span>\n  <span class=\"hljs-attr\">script:<\/span>\n    <span class=\"hljs-bullet\">-<\/span> <span class=\"hljs-string\">echo<\/span> <span class=\"hljs-string\">\"Hello Gitlab-Runner\"<\/span>\n<\/code><\/pre>\n<p><strong>3. Create a docker container with your project dir mounted<\/strong><\/p>\n<pre class=\"lang-yaml s-code-block hljs\"><code><span class=\"hljs-string\">docker<\/span> <span class=\"hljs-string\">run<\/span> <span class=\"hljs-string\">-d<\/span> <span class=\"hljs-string\">\\<\/span>\n  <span class=\"hljs-string\">--name<\/span> <span class=\"hljs-string\">gitlab-runner<\/span> <span class=\"hljs-string\">\\<\/span>\n  <span class=\"hljs-string\">--restart<\/span> <span class=\"hljs-string\">always<\/span> <span class=\"hljs-string\">\\<\/span>\n  <span class=\"hljs-string\">-v<\/span> <span class=\"hljs-string\">$PWD:$PWD<\/span> <span class=\"hljs-string\">\\<\/span>\n  <span class=\"hljs-string\">-v<\/span> <span class=\"hljs-string\">\/var\/run\/docker.sock:\/var\/run\/docker.sock<\/span> <span class=\"hljs-string\">\\<\/span>\n  <span class=\"hljs-string\">gitlab\/gitlab-runner:latest<\/span>\n<\/code><\/pre>\n<p><strong>4. Execute with<\/strong><\/p>\n<pre class=\"lang-yaml s-code-block hljs\"><code><span class=\"hljs-string\">docker<\/span> <span class=\"hljs-string\">exec<\/span> <span class=\"hljs-string\">-it<\/span> <span class=\"hljs-string\">-w<\/span> <span class=\"hljs-string\">$PWD<\/span> <span class=\"hljs-string\">gitlab-runner<\/span> <span class=\"hljs-string\">gitlab-runner<\/span> <span class=\"hljs-string\">exec<\/span> <span class=\"hljs-string\">docker<\/span> <span class=\"hljs-string\">test<\/span>\n<\/code><\/pre>\n<p><strong>5. Prints<\/strong><\/p>\n<pre class=\"lang-yaml s-code-block hljs\"><code><span class=\"hljs-string\">...<\/span>\n<span class=\"hljs-string\">Executing<\/span> <span class=\"hljs-string\">\"step_script\"<\/span> <span class=\"hljs-string\">stage<\/span> <span class=\"hljs-string\">of<\/span> <span class=\"hljs-string\">the<\/span> <span class=\"hljs-string\">job<\/span> <span class=\"hljs-string\">script<\/span>\n<span class=\"hljs-string\">$<\/span> <span class=\"hljs-string\">echo<\/span> <span class=\"hljs-string\">\"Hello Gitlab-Runner\"<\/span>\n<span class=\"hljs-string\">Hello<\/span> <span class=\"hljs-string\">Gitlab-Runner<\/span>\n<span class=\"hljs-string\">Job<\/span> <span class=\"hljs-string\">succeeded<\/span>\n<span class=\"hljs-string\">...<\/span>\n<\/code><\/pre>\n<p><strong>Note:<\/strong> The runner will only work on the <strong>commited<\/strong> state of your code base. Uncommited changes will be ignored. <strong>Exception<\/strong>: The <code>.gitlab-ci.yml<\/code> itself must not be commited to be taken into account.<\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>I use this docker-based approach. 0. Create a git repo to test this mkdir my-git-project cd my-git-project git init git commit &#8211;allow-empty -m&#8220;Initialize repo to showcase gitlab-runner locally.&#8220; 1. Go to your git directory cd my-git-project 2. Create a .gitlab-ci.yml Example .gitlab-ci.yml image: alpine test: script: &#8211; echo &#8222;Hello Gitlab-Runner&#8220; 3. Create a docker container [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,6,9],"tags":[],"class_list":["post-1786","post","type-post","status-publish","format-standard","hentry","category-admin","category-development","category-java"],"_links":{"self":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/1786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/comments?post=1786"}],"version-history":[{"count":1,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/1786\/revisions"}],"predecessor-version":[{"id":4011,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/posts\/1786\/revisions\/4011"}],"wp:attachment":[{"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/media?parent=1786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/categories?post=1786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jan.schnasse.org\/blog\/wp-json\/wp\/v2\/tags?post=1786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}