2

Is there any way to run a PowerShell script in Sitecore using Gulp? We are trying to integrate some content publishing to the build process automatically. All our JS/CSS is stored in the Media Library which needs to be manually published each time there is a new build so we want to automate this task.

1
  • SXA CLI does this. You might explore their code. Commented Oct 17, 2022 at 16:29

1 Answer 1

2

PowerShell is a great choice for dealing with Sitecore items. Assume that you already have your somescript.ps1 script ready and want to run it from a Gulp task while building & deploying your project files. The below script will help you to achieve this:

gulp.task('your-task', function (cb) {
    var psScriptPath = "your-script-path";
    exec('powershell.exe -file ' + psScriptPath + 'somescript.ps1', function (err, stdout, stderr) {
        console.log(stdout);
        console.log(stderr);
        cb(err);
    });
});
2
  • Thanks Kate, do you know how the script could publish files to the website? If I run the ps1 file from the CMS it works fine, but I want to be able to run a script during development so that when I modify a JS file and its uploaded to the media library for instance, then it will Smart publish the respective Theme folder so the changes will be made live automatically. Thanks in advance Commented Oct 18, 2022 at 11:24
  • Did you consider creating an item:saved event handler if you want to do something extra while updating your asset? Commented Oct 18, 2022 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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