Hi,
We use in our project a javascript CLI for dev related tasks and we wanted to cache the compiled version across workflows as it changes less the code. To do so, I tried the following code:
install_standalone_cli:
steps:
- restore_cache:
keys:
# `git log -n 1 --pretty=format:%H -- cli/` finds the last commit hash modifying the cli folder
- javascript-cli-v1-{{ git log -n 1 --pretty=format:%H -- cli/ }}
- run:
name: Compile CLI
command: |
rm -rf cli/lib cli/tsconfig.tsbuildinfo
yarn build-cli
yarn compile-cli
- save_cache:
key: javascript-cli-v1-{{ git log -n 1 --pretty=format:%H -- cli/ }}
paths:
- ./myCliExecutable.js
This command is called in the following job:
sonar_analysis:
executor: jdk17-docker
resource_class: large
working_directory: ~/myProject
environment:
MVN_REPO: /home/circleci/.m2/repository
MVN_SETTINGS: .circleci/resources/settings.xml
steps:
- checkout
- restore_java_cache
- install_cli
- compile_project:
parallel: -T 1C
- run:
name: Analyse project
command: |
if [ -n "$CIRCLE_PULL_REQUEST" ]
then
GITHUB_PULL_REQUEST_ID=${CIRCLE_PULL_REQUEST##*/}
mvn --settings .circleci/resources/settings.xml -Dmaven.repo.local=${HOME}/.m2/repository \
-Dsonar.pullrequest.base=$VERSION \
-Dsonar.pullrequest.branch=$CIRCLE_BRANCH \
-Dsonar.pullrequest.key=$GITHUB_PULL_REQUEST_ID \
sonar:sonar
else
mvn --settings .circleci/resources/settings.xml -Dmaven.repo.local=${HOME}/.m2/repository \
-Dsonar.branch.name=${CIRCLE_BRANCH} \
sonar:sonar
fi
With the following definition for the executor and other commands:
jdk17-docker:
docker:
- image: cimg/openjdk:17.0.5-node
install_cli:
steps:
- install_javascript_env
- install_standalone_cli
Unfortunately, the caching/restoring steps always fails in the job with the following error message:
error computing cache key: template: cacheKey:1: function "git" not defined
I don’t understand why that fails, as per documentation (cimg/openjdk - CircleCI) git is contained in that image.
Thanks in advance !