I'm using Gulp in an Azure devops pipeline. The task is to bundle some CSS files using gulp-concat, then publish the artifact.
One task runs Gulp using this...
const gulp = require("gulp"),
concat = require("gulp-concat"),
fs = require("gulp-fs");
function doBundle(callback) {
var result = gulp.src([
...
])
.pipe(concat("bundle.css"))
.pipe(gulp.dest("./Content/"));
console.info(fs.existsSync("./Content/bundle.css"));
return result;
}
gulp.task("default", gulp.series(doBundle));
The subsequent task in the pipeline publishes the artifact found at ./Content/bundle.css, but this fails, saying that no such file exists.
True enough, looking at the console I can see that the line...
console.info(fs.existsSync("./Content/bundle.css"));
...is returning false. However, if I introduce a delay by changing that line to...
setTimeout(() => {
console.info(fs.existsSync("./Content/bundle.css"));
},
2000);
... then it returns true.
My assumption is therefore that the devops pipeline is moving to the next task before the Gulp task has completed. If this is correct, what's the best practice here?
How can I ensure that the Gulp pipeline has completed before the next task in the Azure devops pipeline?