I would to know how I can run a drush command like drush @alias cc all with a gulp workflow ?

This is my starting code:

var plugins = require('gulp-load-plugins')();
    gulp.task('drush:cc', function () {

      return gulp.src(source)
          'drush @vmdevd6mg cc all'
          title: "Caches cleared",
          message: "Drush Drupal CSS/JS caches cleared.",
          onLast: true

Thanks EDIt: another way to run drush but seem not to work too,no error message given.

// Run drush to clear the theme registry.
gulp.task('drush', plugins.shell.task([
   'drush @vmdevd6mg cc all'

both tasks give:

gulp drush 
Error: spawn drush @vmdevd6mg cc all ENOENT

EDIT1: New test

My new task and the result:

//Vidage de cache Drupal avec Drush
gulp.task('drush', function() {
  return gulp.src(basePaths.drushscript, {
      read: false

      'drush @vmdevd6pf cron && drush @vmdevd6pf cc all'

      title: "Vidage de Cache",
      message: "Cache Drupal vidé complètement.",
      onLast: true

Part of the global launch task:

gulp.watch(folderPaths.js.jsd68, ['drush']);


 /bin/sh: 1: drush: Permission denied

          throw er; // Unhandled 'error' event
    Error: Command `drush @vmdevd6pf cron && drush @vmdevd6pf cc all` failed with exit code 127

EDIT: final gulp task work like //Vidage de cache Drupal avec child_process - 2020-06

gulp.task('drush-cp', function(done) {
  return cp.spawn('drush', ['cache-rebuild'], {stdio: 'inherit'})
  .on('close', done)
   /*  .pipe(plugins.notify({
    title: "Vidage de Cache avec Drush",
    message: "Cache Drupal vidé complètement.",
    onLast: true
  })); */
  • Well, have you installed gulp shell plugin?
    – Kevin
    Apr 28 '17 at 10:12
  • yes I did install it. May 2 '17 at 14:24
  • What is supposed to call this task?
    – Kevin
    May 2 '17 at 14:25
  • This task is suppose to clear cache of a D6 site with using drush 8 and alias May 3 '17 at 9:10
  • No., what calls this task?
    – Kevin
    May 3 '17 at 10:50


The first thing you’ll need is to import the dependency for “child process.” Next, you’ll want to set up an array variable containing all the paths to files you want auto-cache clearing setup for. This will basically be any Drupal template file. I would start with the main template directories you know you need it set up for and then add the additional paths along the way. Once we have our variables set, we then build our “clearcache” task using the “child_process” dependency that is shown below. Once we have all the pieces setup, we combine them in a watch task and let the magic happen! Using this task in your workflow will save you so much time, and even more importantly, save you the headache of clearing your cache every 2 minutes.

If you do run into some issues having your task running, make sure your Drush is setup and working in your command line as these Gulp task relies on Drush to complete its work.


var cp = require('child_process');
var drupal_files = "paths/to/your/drupal/files/you/want/auto-cache-clearing";
// Clearcache Task
gulp.task('clearcache', function(done) {
  return cp.spawn('drush', ['cache-rebuild'], {stdio: 'inherit'})
  .on('close', done);
gulp.watch(drupal_files, ['clearcache']);

Source: http://serversideguy.com/2018/02/05/how-can-i-automatically-clear-cache-for-drupal-using-gulp/

  • I'm back on this. Where can I find more doc about using child process ? For my need, I use drush alias, so the command is different from this example. Thanks Jun 4 '20 at 8:10
  • Task work with nodejs chilp process. Added in a watch task like the edited post. Thanks Jun 4 '20 at 12:14
  • Do I need to use the alias to clear cache from specific website ? adding it in the task break it actually. Jun 18 '20 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.