1

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?

christianeide
  • 417
  • 2
  • 13

1 Answers1

0

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

Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52
  • Your comment sent me in the right direction. My solution was to move the entire docker-build-command into its own file, *docker-build.sh*, and then run this file from package.json. *bash .docker/docker-build.sh* – christianeide Jun 19 '17 at 07:52