title: How to share cache on gitlab-runner when concurrent jobs
body: <p>I have a code that I test using gitlab-ci.
  Previously, I was using a shared gitlab-runner, and everything was fine.</p>
  <p>I recently migrated to a gitlab-runner hosted by my company, and the exact same code is no longer valid through the gitlab-ci pipeline.
  The error raised was:</p>
  <pre><code>Executing &quot;step_script&quot; stage of the job script 00:05
  Using docker image sha256:xxx for registry.gitlab.com/me/myproject/myimage with digest registry.gitlab.com/me/myproject/myimage@sha256:xxx ...
  $ cd build
  /bin/bash: line 125: cd: build: No such file or directory
  </code></pre>
  <p>I investigate and found a problem about the cache shared.
  Indeed, my cache is shared between different jobs working concurrently at the same stage, but on shared runner freely available it was not an issue.
  So, I switch my gitlab-runner configuration in order to have no concurrent jobs (ie. <code>concurrent = 1</code> in the file <code>/etc/gitlab-runner/config.toml</code>), resulting no cache problem anymore.
  I conclude that the issue is more about the gitlab-runner configuration.
  My current configuration file <code>/etc/gitlab-runner/config.toml</code> is:</p>
  <pre><code>concurrent = 8
  check_interval = 0
  
  [session_server]
  session_timeout = 1800
  
  [[runners]]
  name = &quot;MY-RUNNER-NAME&quot;
  url = &quot;https://gitlab.com/&quot;
  token = &quot;MY-TOKEN&quot;
  executor = &quot;docker&quot;
  [runners.custom_build_dir]
  [runners.cache]
     Shared = true
     [runners.cache.s3]
     [runners.cache.gcs]
     [runners.cache.azure]
  [runners.docker]
     tls_verify = false
     image = &quot;IMAGE:latest&quot;
     privileged = true
     disable_entrypoint_overwrite = false
     oom_kill_disable = false
     disable_cache = false
     volumes = [&quot;/cache&quot;]
     shm_size = 0
  </code></pre>
  <p>So how to configure my runner to allow concurrent jobs to share their caches (or solve this conflict) ?</p>
  <h1>EDIT</h1>
  <p>Here is my <code>gitlab-ci.yml</code> file:</p>
  <pre><code># GitLab-CI configuration file.
  
  stages:
    - prepare
    - build
    - test
  
  .allConfigs:
    parallel:
      matrix:
        - DISTRIBUTION: ['alpine']
          COMPILER: ['gcc'] 
    image: ${CI_REGISTRY_IMAGE}/${DISTRIBUTION}-${COMPILER}
    cache:
      key: ${DISTRIBUTION}-${COMPILER}-key
      paths:
        - build/
        - external/
    
  
  prepare:
    stage: prepare
    script:
      - git reset --hard HEAD 
      - git clean -d -f -x
      - mkdir build
      - cd build
      - cmake ../
      - make update
    extends: .allConfigs
  
  
  build-exe:
    stage: build
    script:
      - cd build
      - cmake ../ #-DTESTING=OFF
      - make main
      - make install
    extends: .allConfigs
  
  
  test-integration:
    stage: test
    script:
      - cd build
      - cmake ../ -DTESTING=ON
      - make integrationTest
    extends: .allConfigs
    
  test-unit:
    stage: test
    script:
      - cd build
      - cmake ../ -DTESTING=ON
      - make unitTest
    extends: .allConfigs
  </code></pre>
  <p>The error mentioned appears when the 2 test jobs are executing concurrently.</p>