<p>I'm running gitlab 10.4.3 with gitlab-runner 10.4.0 as a kubernetes deployment with kubernetes runner and a minio-server for caching. I installed it according to the <a href="https://docs.gitlab.com/runner/install/autoscaling.html#install-the-cache-server" rel="nofollow noreferrer">gitlab docs</a>.</p>
<p>Everything worked with the cache as expected, when adding the appropriate settings to the <code>.gitlab-ci.yml</code>-file:</p>
<pre><code>build:
  stage: build
  variables:
    GIT_STRATEGY: fetch
  cache:
    key: &quot;$CI_COMMIT_REF_NAME&quot;
    paths:
      - node_modules/
  script:
    - compile-templates.sh
    - yarn install
    - yarn run build
</code></pre>
<p>The pipeline output did fill the cache the first time and subsequent runs on the same branch correctly pulled and pushed the cache:</p>
<pre><code>Running on gitlab/runner-abcdefg-project-123-concurrent-123456 via gitlab-runner-123456-987654...
Cloning repository for feature/gitlab-cache with git depth set to 1...
Cloning into '/group/project'...
Checking out b1348594 as feature/gitlab-cache...
Skipping Git submodules setup
Checking cache for feature/gitlab-cache...
Downloading cache.zip from http://minio-service:9000/runner/runner/abcdefg/project/123/feature/gitlab-cache 
Successfully extracted cache
$ docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
Login Succeeded
[...snip...]
Creating cache feature/gitlab-cache...
node_modules/: found 26281 matching files
Uploading cache.zip to http://minio-service:9000/runner/runner/abcdefg/project/123/feature/gitlab-cache 
Created cache
</code></pre>
<p>However, after some runs it suddenly stopped working - and I do not know why. I've also tried a job-global cache-definition to no avail - it seems that the gitlab-runner is simply ignoring the setting and just skips the &quot;Checking cache part&quot;:</p>
<pre><code>Running on gitlab/runner-abcdefg-project-123-concurrent-123456 via gitlab-runner-123456-987654...
Cloning repository for feature/gitlab-cache with git depth set to 1...
Cloning into '/group/project'...
Checking out b1348594 as feature/gitlab-cache...
Skipping Git submodules setup
$ docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
Login Succeeded
[...snip...]
Job succeeded
</code></pre>
<p>My gitlab-runner config.toml has the appropriate settings:</p>
<pre><code>[[runners]]
  // ...
  [runners.kubernetes]
  // ...
  [runners.cache]
    Type = &quot;s3&quot;
    // I've also tried http://minio-service:9000 to no avail
    ServerAddress = &quot;minio-service:9000&quot;
    AccessKey = &quot;xxxxxxxxxxxxxxxxxxxxxxxx&quot;
    SecretKey = &quot;xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&quot;
    BucketName = &quot;runner&quot;
    Insecure = true
</code></pre>
<p><em>Note:</em> If I change the settings to invalid ones, I do not get any error messages in the runners logs.</p>
<p>The port is reachable from the runner itself <em>and</em> from job pods:</p>
<pre><code>$ curl -s &quot;http://minio-service:9000&quot;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;Error&gt;&lt;Code&gt;AccessDenied&lt;/Code&gt;&lt;Message&gt;Access Denied.&lt;/Message&gt;&lt;Key&gt;&lt;/Key&gt;&lt;BucketName&gt;&lt;/BucketName&gt;&lt;Resource&gt;/&lt;/Resource&gt;&lt;RequestId&gt;12345&lt;/RequestId&gt;&lt;HostId&gt;12345&lt;/HostId&gt;&lt;/Error&gt;
</code></pre>
<p>The bucket on minio exists as checked in the local volume <em>and</em> via the minio client <code>mc</code>.</p>
<p>There are no errors in the logs of the pods of gitlab-runner or the minio-server.</p>
<p>It's just like the cache-settings of the <code>.gitlab-ci.yml</code> are simply ignored and I'm out of ideas on what's left to check. Anyone with any ideas?</p>

<p>So, the problem was an invalid documentation in combination with a silent ignore of invalid cache:keys. If a branch is e.g. named <code>feature/some-new-thing</code>, the resulting key of <code>&quot;$CI_COMMIT_REF_NAME&quot;</code> would lead to an invalid cache:key containing a &quot;/&quot;-character - which in turn would render the whole cache-section invalid, but which is silently ignored.</p>
<p>Instead, just use <code>&quot;${CI_BUILD_REF_SLUG}&quot;</code>, which will contain an url-safe - and therefore cache:key-safe - version of the branch name:</p>
<pre><code>cache:
  key: &quot;${CI_BUILD_REF_SLUG}&quot;
  paths:
    - node_modules/
</code></pre>
<p>A <a href="https://gitlab.com/gitlab-org/gitlab-runner/issues/3085" rel="nofollow noreferrer">bug report</a> has been opened.</p>
