poor cache policy usability

GitLab 9.4 introduced cache:policy : https://docs.gitlab.com/ce/ci/yaml/#cache-policy

I've been trying to use it, but seems it needs a lot of duplication to get it actually to work.

As there's no way to tell which cache key to use, need to duplicate whole cache block. i used yaml templates for that.

Scenario:

  1. composer stage that writes cache (and updates)
  2. test1..test9 stages that read cache
stages:
  - composer
  - test

# define yaml templates first
.composer_cache_rw: &composer_cache_rw
  cache:
    key: "$CI_COMMIT_REF_NAME"
    paths:
    - vendor/
    - composer.lock
    - .php_cs.cache
    policy: pull-push

.composer_cache_ro: &composer_cache_ro
  cache:
    key: "$CI_COMMIT_REF_NAME"
    paths:
    - vendor/
    - composer.lock
    - .php_cs.cache
    policy: pull

composer:
  <<: *composer_cache_rw
  stage: composer
  image: composer/composer
  script: |
    composer update

test:readonly-1:
  <<: *composer_cache_ro
  stage: test
  image: alpine
  script: |
    ls -l vendor
    ls -l

...

test:readonly-9:
  <<: *composer_cache_ro
  stage: test
  image: alpine
  script: |
    ls -l vendor
    ls -l

i tried to omit paths from readonly jobs -> it failed to download cache at all (it disabled cache?)

i tired to put paths to base yaml-template and override only cache policy -> this resulted again cache failure because likely paths were empty.

some of this may be related how yaml is parsed and how jobs config blocks are merged. seems to me that cache section is reset, not merged:

.composer_cache: &composer_cache
  cache:
    key: "$CI_COMMIT_REF_NAME"
    paths:
    - vendor/
    - composer.lock
    - .php_cs.cache

composer:
  <<: *composer_cache
  stage: composer
  image: composer/composer
  script: |
    composer update
  cache:
    policy: pull-push

this seems to result empty paths for composer job.

ideally, for readonly cache jobs, i would like to define only cache.key and cache.policy, also it would be awesome if i could specify multiple cache.key to be pulled and merge, something like already exists for artifacts (using dependencies)

Assignee Loading
Time tracking Loading