I have a package.json that contains this script:
"scripts": {
"docker-build": "docker build -t url.com/repository:$(git rev-parse --short HEAD) ."
}
I use this to create automatic tags from Git on mye Docker-images. This works on Mac, but not on a Windows-machine running Docker Quickstart Terminal.
Is it possible to run the $(git rev-parse --short HEAD)
command from NPM-script on Windows?
Unfortunately, even though you might have a bash environment on your windows system, the npm scripts
will think they have to run in a Windows shell. (This lack of cross-platform portability is one of the big limitations of npm scripts.)
If having platform-specific scripts is ok, then you could refer to this question for how to do something similar in a windows shell: Batch equivalent of Bash backticks