Environment variable in checksum


#1

It seems environment variables are not available in the {{ checksum “filename” }} template. The filename that I want to checksum depends on an environment variable… Is there any way for this to work?


#2

Just echo the contents of the env var into a file and get the checksum.


#3

I can’t figure out how to make that work.

This is what I’m trying, but it generates a different checksum every time. Are there any hidden salts involved?

- run: pushd base && git_rev_base=$(git describe HEAD) && popd && echo $git_rev_base >git-rev-base
      - restore_cache:
          keys:
            - build-{{ checksum "git-rev-base" }}

#4

Try echoing $git_rev_base to see what you’re dealing with.

Add another restore key to always get a restore:

keys:
  - build-{{ checksum "git-rev-base" }}
  - build-

#5

Oh dear, thank you for stating the obvious! Sometimes a second pair of eyes really helps. :slight_smile: Apparently it’s running git describe head on the main repo rather than the submodule. I’m not sure why that should be the case (as it works just fine locally) but I can work with that.


#6

Figured I should add, the key was that the submodule hadn’t been git inited and git updated yet. Alternatively one could use something like git submodule status base >git-hash-base.


#7