Pro Tip: Using Node.js's child_process with Gulp and Visual Studio's Task Runner Explorer

12 November 2014

A quick tip - had a Gulp task set up to call Git from the command line, get the latest commit hash and append it to some html files, and while it worked on someone else's Mac, it didn't on my machine.

gulp.task('tag', function(){
  shell('git describe --dirty', function(err,stdout) {
    if(err) {
        throw new Error(err);
    }
      gulp.src(['index.html'], { root: base })
    .pipe(replace(/\{\{-git tag\}\}/g, stdout))
    .pipe( gulp.dest( build_dest ) );
  })
});

So it turns out that even though I can run git from a regular old command line, because the Task Runner Explorer spawns as a different user, it doesn't recognize the 'git' command. To fix this, you just need to add the following to the end of your System Environment Variables (in System -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables -> Path):

;C:\Program Files (x86)\Git\bin`

Tags: Gulp, Visual Studio, git

Add a Comment

No Comments