Summary
I'm trying to deploy an MVC5 web app to Azure. I need to set WEBSITE_NODE_DEFAULT_VERSION programatically to ensure all configuration is atomically contained in the repo. When I try to set that app setting / env variable in .deployment
or deploy.cmd
, it gets ignored by the deployment. Why?
Background
My web app uses bower for client-side libraries, and a simple gulp script to place the minimized libs in a target folder. My cshtml files then consume them from said target folder.
Per this comment, I've brought down the deployment script (.deployment
and deploy.cmd
) from Azure and tweaked it to install bower.
Then download your custom deployment script. if you go to https://.scm.azurewebsites.net then click on Tools -> Download custom deployment script or just download it from D:\home\deployment\tools
My research then showed that npm is available by default in Azure web app deployments, and the bower package is pre-installed, but gulp isn't. So I need to add 3 custom commands to the deployment scripts:
- npm install (required to make gulp available)
- bower install (pulls down the client-side libs)
- gulp (pipelines the client-side libs)
Per this question, The problem I'm facing is that node (and therefore npm) being used are an old version. The npm install
command is resulting in filenames that are too long, which is a known issue in older versions of npm.
Per this set of Kudu runtime settings, I'm trying to set the WEBSITE_NODE_DEFAULT_VERSION
to 6.7.0 (the latest at the time of this question), because that would ensure that the latest npm also runs.
Here's where my problem occurs. In deploy.cmd
, before running npm install
, I add a line set WEBSITE_NODE_DEFAULT_VERSION = 6.7.0
(I've tried variations, including with quotes, without spaces around the equal sign, with setlocal
, etc.) I echo %WEBSITE_NODE_DEFAULT_VERSION%
on either side of setting the variable. The output before and after is always 4.4.7.
I tried it in .deployment
as well, to no avail. I even tried changing the position (sometimes before command = deploy.cmd
and sometimes after).
From what I can decipher off the net, at least one of my methods above should work... Why can't I set this app setting / env variable in the deployment script?
Update
According to this question, I can't set the app settings in the .deployment file. This differs from other articles on the net, but it still doesn't explain why SET isn't working in the deploy.cmd file.
Files
.deployment
[config]
;Change node version to change npm version to avoid long-file-name situations
WEBSITE_NODE_DEFAULT_VERSION = 6.7.0
command = deploy.cmd
deploy.cmd
(REDACTED - default stuff)
echo :: 4. NPM Install (borrowing from https://stackoverflow.com/questions/39480274/how-do-i-run-gulp-js-in-my-asp-net-core-project-when-deploying-to-azure-using-gi)
IF EXIST "%DEPLOYMENT_TARGET%\package.json" (
:: Set the node version. Tried this in .deployment, but that didn't work.
:: HELP! Why isn't this working???
echo %WEBSITE_NODE_DEFAULT_VERSION% before set
:: Output: "4.4.7 before set"
SET WEBSITE_NODE_DEFAULT_VERSION=6.7.0
echo %WEBSITE_NODE_DEFAULT_VERSION% after set
:: Output: "4.4.7 after set"
pushd "%DEPLOYMENT_TARGET%"
call :ExecuteCmd npm install
IF !ERRORLEVEL! NEQ 0 goto error
popd
)
echo :: 5. Bower Install (borrowing from https://stackoverflow.com/a/28591913/1876622)
IF EXIST "%DEPLOYMENT_TARGET%\bower.json" (
pushd "%DEPLOYMENT_TARGET%"
call :ExecuteCmd bower install
IF !ERRORLEVEL! NEQ 0 goto error
popd
)
echo :: 6. Run Gulp (borrowed from https://blogs.msdn.microsoft.com/azureossds/2016/08/12/run-npm-bower-composer-gulp-grunt-in-azure-app-services-during-deployment/)
IF EXIST "%DEPLOYMENT_TARGET%\gulpfile.js" (
pushd "%DEPLOYMENT_TARGET%"
call :ExecuteCmd gulp
IF !ERRORLEVEL! NEQ 0 goto error
popd
)