Unable to Transform JavaScript Files using Powershell script in Octopus


I need help in Transforming JavaScript files using Powershell script in Octopus.

Below are the Steps i have done for transforming. but it’s not happening.

  1. Wrote powershell script to replace value with Env value.
    “(Get-Content ($GlobalConfigurationFile)) | ForEach-Object {$_.replace(‘localhost’, ‘#{environmentwebbinding}’).replace(‘cmsportal.com’, ‘#{environmentwebbinding}’)} | Set-Content -Encoding UTF8 ($GlobalConfigurationFile)”
    In this case, the value of “localhost” need to change to “Env” Value which was specified in Octopus variables.

  2. I’m not using “Substitute variables in files” feature for Transformations. Because, i’m not doing Package Deployment.

Please look attachment for script which i’m using and help me out to fix this issue asap.
if possible, i would like to have call with u guys

Thanks, SathishTransformation script for JS files (1.2 KB)

Hi Sathish,

Thanks for reaching out with this issue regarding javascript substitution,

When you run your script - what actually happens? Are you seeing some errors or exceptions in your Task log? If so, please could you send them through to help me troubleshoot any errors you are getting. Feel free to take some screen shots of what happens on in the Octopus server UI and link me to them here.

Does it look something like this?

If so, please double check your paths, because your script works successfully, when the paths are OK :slight_smile:

Also, lines 10 & 13 appear to be redundant so watch out for those two, if you need to modify lines 5 & 6, lines 10 & 13 would overwrite those changes.

Another option here is to bundle these javascript files into their own zip file, and deploy these files seperately, so that you can use the Package Deployment features to do the substitution for you.

Hope this helps


Hi Jim,

I’m trying to transform JS files using “Substitute variable in files” feature. but its not happening.
Tried below syntax.
In the above case config is transforming and JS files aren’t.
Getting below warning for (*.config, *.js) Substitute variable in files.
*.js, *.js, Test\folder*.js along with *.config)Transform

Please help me out with solution how to transform Js files using “Substitute variables in files”.

Thanks, Sathish

Hi Sathish,

That warning is telling us that no files were found matching that glob pattern (*.config) - indicating that your package may not have files where you expect them to be?

You can confirm this by retrieving the package from D:\Octopus\Files\CMS.Portals@S0003.1.4@2CB0584B8DA6AD4599D97D2CCE6B2007.nupkg on your deployment target, convert that to a .zip file and decompress it manually - so that you can have a look at the package contents.

That way you can make sure the .js and .config files are where you expect them to be.

In case that isn’t the issue - could you please take a screenshot of your “Substitute variable in files” setting in the deployment process, so that I can see how you’ve set this up?

Thanks, Jim

Hi Jim,

Transformation of config is happening. My concern is about transformation of JavaScript file.

  1. I tried 2 scenario’s after extracting the package from the path you suggested. Actually, Javascript files are in Modules\Global\Scripts\Configuration*.js. so i’m giving the path as in below screen shots. en=ven though, the variables are not reflecting.
  2. Variable name is updated because the name is coming from Jenkins. when comes to octopus the variable value should substitute in pace of #{example}.

please look below screen shots.

Thanks, Sathish

Hi Sathish,

Thanks for this detail, it really helps me see what you are trying to do, and how you’ve gone about it!

The values in ‘Substitute Variables in Files’ need to be newline separated, not comma delimited, as you have done here.

Regarding the help text underneath the text box, I understand that the text after the “E.g.” could be a little bit confusing, as it seems to indicate that you could use a ‘,’ character between each pattern, unfortunately though, that is not the case - newlines must be used here.

Could you try removing the ‘,’ char between the two glob patterns and separating them by a new line for each pattern, and let me know how that goes?

Kindest regards,


Hi Jim,

Thanks for your support in resolving my issue.
Now, JavaScript files are Transforming.

Thanks, Sathish

That is great news Sathish, I’m glad I could help.

Happy deployments!


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.