Cache directory name (key for cache) have some symbols

Hi!

I’m trying to undestend some steps of yaml:

in yaml I’m set cache paramets:

cache:
paths:
key: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
policy: push

after that I’m open directory with cache and see
directory have name, like as:
branch_name-fa83b4ca-2

at this situation I’m can’t undestend where are from this “2”?
2 - thisis not a comit part, couse if set only $CI_COMMIT_BRANCH - name directory was branch_name-2

Hi @vic
the -2 suffix is a cache “version” and is added automatically by GitLab. Cache starts with no suffix, then after first time someone clicks on the “Clear runner caches” in Pipeline UI (or use other means to clear runner cache) the suffix -1 is appended. After every runner cache clear the number is incremented.

“Clear runner caches” does not actually delete anything from cache storage. The previous versions are kept there and the suffix is added/incremented to differentiate between them.

1 Like

thank you

I do not know anything about the user function “Clear runner caches” in user interfaces. Only like as function of pipeline.
At this pipeline I’m don’t use cleanup and any people can’t use this job ore cache.

This directory create after first step of this pipeline

Can you help me … where (how) I can set full log of any functions of some pipelene? Where I can find, who change this index?

I don’t know what you mean, cache is optional and it won’t fail any jobs. If you have issues with cache please share your pipeline config.

Docs regarding clearing runner cache is here. I am not sure if it is logged somewhere.

1 Like

my pipeline:

stages:

  • build
  • deploy

job_build_os1:
stage: build
cache:
paths:
- ./
key: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
policy: push
variables:
GIT_DEPTH: “1”
script:
- /opt/develop/cmake-3.9.6/bin/cmake …
- make -jnproc
- echo -e …
artifacts:
name: “$CI_COMMIT_REF_NAME-$CI_COMMIT_SHORT_SHA”
paths:
- build/
expire_in: 4 hours
rules:
- if: ‘$CI_COMMIT_BRANCH =~ /\w*typeone_\w+/ || $CI_COMMIT_BRANCH == “develop/type2” || $CI_COMMIT_BRANCH == “master”’
when: always
- if: $CI_PIPELINE_SOURCE != “merge_request_event”
when: manual
tags:
- os1

job_deploy_os1:
stage: deploy
needs: [job_build_os1]
cache:
key: $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA
policy: pull
variables:
GIT_DEPTH: “1”
script:
- /opt/develop/cmake-3.9.6/bin/cmake …
artifacts:
name: $CI_COMMIT_BRANCH-$CI_JOB_ID-deploy
paths:
- build/.deb
expire_in: 48 hours
rules:
- if: '$CI_COMMIT_BRANCH =~ /\w
typeone_\w+/ || $CI_COMMIT_BRANCH == “develop/type2” || $CI_COMMIT_BRANCH == “master”’
when: on_success
- if: $CI_PIPELINE_SOURCE != “merge_request_event”
when: on_success
tags:
- os1

after job_build in directory “cache” I’m have directory with index ‘2’. job_deploy only pull cache and push artifact.

and if i set static name of cache directory - I’m have problems with multythread builds (on one branch build from the many commits at the same time).

In pipeline I’m block second step (set to manual start) and when first step is over, I’m have same result - directory have index “2”.

Nobody no remove cache on this pipeline. No befoure no after. :frowning:

Hi, did you find the solution? Unfortunately, I’m stuck at the similar point.

that is not a problem
I’m can’t understend this situation where are from this “2”
At the same time this situation don’t destroy my pipeline. For other pipeline in cache key I’m added type of job (build,test,deploy…) and needs and dependence. At now - all pipelines may be runned at the same time and in runner I can set any value for “concurrent”.

And what is your problem?

I am sorry, but I don’t understand what are you trying to achieve. GitLab Runner cache is transparent to jobs and there is no need to specify or use any directory in /cache.

Hi!

Sorry but you wrong :^)

I’m have multisystem project with many moduls on one branch. From the complect of moduls developers collect build. On the main pipeline I’m see many modules, If some developers will (they do it everyday) create multibuild - if cache will constat, thy will push in smame directory of cache - this about tranperent cache %)

system has this parts of build:

test-build-deply-arch-assembling

branch_a {build} >> cache.zip of project_1 (cache1)
after
branch_b {build} >> cache.zip of project_2 (cache2)

if i’m set names from static_names - they will push in the same directory, and after this I will have:

branch_a {deploy} << cache.zip of project_2

this one of problem what was find

and now, if I’m cand undestend “what is a {…}?” And I’m can’t understand from what someone … I’m try tu undestend.

and now with the cache key (cache key - this is name for directory, where cache are stored) I’m use $branch-$commit-$step-$project
and if i look in directory with cache, I’m see:
$branch-$commit-$step-$project-2
and now I’m try to understand … source of this “2” :-/

I have already explained to you where the -2 suffix comes from. It’s added by GitLab automatically and there is nothing you can do about it. There is no option to change or disable it.

Now I understand that your problem is that jobs from different modules in your repository overwrite cache. This is expected behavior and explained in the documentation. It is also noted there that cache is not designed to transfer files between jobs. That’s what artifacts is for. If you need separate cache for each module you must use unique cache.key in each module’s jobs. Something like $CI_COMMIT_BRANCH-$CI_COMMIT_SHORT_SHA-module1

I still don’t understand, why are you concerned with names of the directories in cache. That’s internal GitLab Runner directory which should not be accessed or manipulated by anything else.

thank you, yes, I rememer what you write befoure.

names of directorys - I’m need to undestand all elemets of mechanics work GitLab for understand “how it works”.

about “2” - if I set static names of directories, what creating on runners - “2” dont added to name of directories. Only static names. And creation only “2” for pipeline have any quantity of stages.

cache - why cache we cant use for move result of stages between stages (for up speed of works)? In manual for gitlab writes about cache and artifacts. I can use artifacs, but cache can optimizatet speed.

alot of thanks for your answer and your time for answer :slight_smile: