Conditionally Naming Cache Keys

I’m building up a workflow to run some builds as tags get pushed.

I’ve read through the documentation, and was disappointed to learn that there is no template such as:
{{ .Tag }} that acts in a similar vein to {{ .Branch }}

Which got me wondering: is it possible to conditionally name the cache that I want to save using environment variables?
This would save me having to have a second checkout job specifically for tag workflows.

Yes, you can, in fact, there’s an example in the docs, though it’s not mentioned in the EnvVars doc. I think I’ve just found a PR I could do.

There is the link - https://circleci.com/docs/2.0/sample-config/#sample-configuration-with-fan-infan-out-workflow and and example below for easy reference of anyone looking in discuss.

- save_cache:
    key: v1-repo-{{ .Environment.CIRCLE_SHA1 }}
    paths:
      - ~/circleci-demo-workflows

UPDATE: In starting to write the PR, I’m not 100% sure if you can use any arbitrary environment variables or just the CircleCI built-in ones. I plan to test with project defined environment variables in addition to ones created in the job using the $BASH_ENV interpolation workaround.

See here.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.