Variable substitution not working in javascript file

Hi,

Using Octopus 3.2.4-bugfix-loglines0056, I am trying to do some variable substitution into a javascript file created with webpack

You can see the variable definition in the attached screenshot and in my source javascript file I have:
`var test = “#{Wsf.Host}”;

which is transformed using webpack (before the nuget package is created) into
`var l="#{Wsf.Host}";
Though note that this is not on a line on it’s own - it is mixed in with a bunch of other javascript on the same line which has been minified by webpack, hence the variable name change.

The configuration of the “Substitute variables in files section” of the process specifies
`configuration.*.bundle.js

and the file name itself, which changes every time it is webpacked, is
`configuration.cdff324f4fba11c9aab9.bundle.js

I can see this line in the log file showing it has found the file:

Performing variable substitution on 'D:\Octopus\Applications\DEV\XXXX\configuration.cdff324f4fba11c9aab9.bundle.js'

but no substitution has been performed.

I am deploying to the DEV environment and the value is marked in Octo to go to DEV. I have also tried with values with no specific target and still no joy

Could it just be that Octo doesn’t like the webpacked code and the line requiring substitution needs to be on a line on it’s own in the file, or am I missing something else obvious?

thanks

variable.jpg

configuration.jpg

Hi Tony,

Thanks for reaching out. My initial hunch tells me that the variable on the JS file is not being properly defined. Could you help me with the following?

  • Can you send me the full file D:\Octopus\Applications\DEV\XXXX\configuration.cdff324f4fba11c9aab9.bundle.js. I’m interested in seeing the state of that file once it was deployed to the Tentacle.

  • Can you follow the below instructions and send me a deployment log? If possible, try to only run the package deploy step.

1) Add these 2 variables to your project http://docs.octopusdeploy.com/display/OD/Debug+problems+with+Octopus+variables

2) Create a new release (so the new variables take effect) and deploy it. If possible skip as many steps as you can and only leave step we are troubleshooting in order to avoid the noise in the log.

3) Send us the raw log of that deployment http://docs.octopusdeploy.com/display/OD/Get+the+raw+output+from+a+task

Thanks,
Dalmiro

Hi,

Apologies for the delay - I have been on holiday

Attached is the .js file and the log file as requested.

Note that the file name changes every time there is a build (to defeat web caches) so this one is called configuration.19f944f5d54abc599954.bundle.js

You can see the log file says:
4202 10:56:00 Info | Performing variable substitution on ‘D:\Octopus\Applications\DEV\Web_UBS.Delta.Web.Apps\0.1.158\configuration.19f944f5d54abc599954.bundle.js’

But you can also see that the .js file still contains var l="#{Wsf.Host}"

Any thoughts?

Cheers

Tony

Hi Tony,

Sorry for the delay here.

I was able to reproduce this bug. Turns out you have the chars #{ in the file body, and Octopus thinks that’s an incomplete variable so it decides not to replace anything at all. I’ve filed a github issue to get this bug fixed: https://github.com/OctopusDeploy/Issues/issues/2623

Unfortunately I can’t think of any workaround besides skipping the minification of that particular file until we get this fixed. If that #{ actually comes from your own code and its not something created by the minifier, perhaps you could do something like # + { just so in the final minifed file you don’t get those 2 chars next to each other.

Sorry for the inconveniences.

Best regards,
Dalmiro

Hi Dalmiro,

I don’t get it - the #{…} is exactly what your documentation says is needed for variable substitution - every instance of that in the file is to substitute a variable
The only ones I can think it could be tripping up on are the ones of the form #{A[B]} - which are also valid to us anyway.

We have this strange problem where different processes in the same project need variables with the same name but different values.
For example, websites A and B needs say setting Foo.Bar so we have defined octo variables Foo.Bar[A] and Foo.Bar[B]
We have a custom install script which then takes these and makes a Foo.Bar variable which is then substituted into the web.config, again using custom code.
This all works well.

The problem now is trying to use the standard Octo mechanism to substitute in a variable, which will happen, as I understand it, before the scripts are run - so in my script I have to reference the full #{Foo.Bar[A]} syntax.

Do you have a timescale for when the issue will be fixed - and indeed will hopefully support #{Foo.Bar[A]} as a valid variable ?

Thanks

Tony

Hi,

Upon checking again, I realise we have this code:

if (value.substr(0, 2) === ‘#{’) {
return undefined;
}
else {
return value;
}

This is there to allow us to work locally without Octo variable substitution so I changed it to be ‘#’ + ‘{’ but minification recombined them again :}

I have changed it to this:

const start = ‘#’;
const openBracket = ‘{’;
const octoPrefix = start + openBracket;
if (value.substr(0, 2) === octoPrefix) {
return undefined;
}
else {
return value;
}

and it worked - it’s a bit hacky though and would obviously prefer not to do this so if you can fix Octo then that would be great

thanks

Tony

From: Butler, Tony-A
Sent: 08 August 2016 07:18
To: 'Dalmiro Grañas’
Subject: RE: Variable substitution not working in javascript file [Problems #46715]

Hi Dalmiro,

I don’t get it - the #{…} is exactly what your documentation says is needed for variable substitution - every instance of that in the file is to substitute a variable

The only ones I can think it could be tripping up on are the ones of the form #{A[B]} - which are also valid to us anyway.

We have this strange problem where different processes in the same project need variables with the same name but different values.

For example, websites A and B needs say setting Foo.Bar so we have defined octo variables Foo.Bar[A] and Foo.Bar[B]

We have a custom install script which then takes these and makes a Foo.Bar variable which is then substituted into the web.config, again using custom code.

This all works well.

The problem now is trying to use the standard Octo mechanism to substitute in a variable, which will happen, as I understand it, before the scripts are run - so in my script I have to reference the full #{Foo.Bar[A]} syntax.

Do you have a timescale for when the issue will be fixed - and indeed will hopefully support #{Foo.Bar[A]} as a valid variable ?

Thanks

Tony

Hi Tony,

Its great that you were able to find a workaround for this. I’m pretty sure we’ll be able to do something about this behavior when we tackle that github issue.

Cheers,
Dalmiro