My justfile looks like this:
export GIT_COMMIT:="$(git show --format="%h" --no-patch)"
docker_build:
docker build -t some/tag:$GIT_COMMIT -t some/tag:latest .
when I run it then I get the following error:
export GIT_COMMIT:="$(git show --format="%h" --no-patch)"
^
So basically just doesn't like %. But it's necessary.
Is there an elegent way to get this to work? I use the GIT_COMMIT variable in a few different places so it would be nice if it was reusable.
So far I'm using this workaround:
docker_build:
GIT_COMMIT="$(git show --format="%h" --no-patch)"; docker build -t some/tag:$GIT_COMMIT .
docker build -t some/tag:latest .
But it gets a bit messy
The problem with your justfile is not the percent sign, it's that you're using the same type of quotes for the outer string and for the inner one.
justis interpreting the second quote as ending the string, and then doesn't know what to do with the bare%.In this case, because the format is just a single string token long with no spaces, you can simply remove the inner quotes entirely:
But if you actually needed the format to have spaces, you could use alternating quotes like this:
Even more options in the
Justmanual section on strings. You could also use backticks to save the result of the command to thejustvariable instead of saving the string of the unevaluated bash command substitution.