projectkudu/KuduScript

New deploy.batch.functionApp.template file not working

Closed this issue · 4 comments

I'm encountering two (seemingly) syntactical errors with the new deploy script:

  1. {sitePath} is not substituted in the kudusync command call. When removing it, the script seems to generate the correct paths:

  1. Error checking does not seem to work correctly. The statement IF !ERRORLEVEL! NEQ 0 goto error does not seem to substitute !ERRORLEVEL! for the actual value of ERRORLEVEL. %ERRORLEVEL% is substituted, but is of course the value of ERRORLEVEL at the beginning of the script, not at that point in the script.

The file has been stored as kudu-deploy.cmd and the .deployment file contents are:

[config]
command = kudu-deploy.cmd

I have also tried renaming kudu-deploy.cmd to kudu-deploy.bat, which produces the exact same result.

Could you confirm these problems or perhaps indicate what we might be doing wrong?

Additionally, when removing these statements (which does allow the whole script to run), I run into an additional error when executing the line

call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd;node_modules"

, with the error: The system cannot find the batch label specified - ExecuteCmd

Are you saying that without removing {SitePath} from the template, you are getting something likeD:\home\site\repository{SitePath}?

I am guessing that you are saving this function template as your kudu-deploy.cmd? instead of using the output of the kuduscript.js which replace {SitePath} in the template and define additional label (ExecuteCmd)

for example: I run
node kuduscript -y --no-dot-deployment -r "D:\FunctionAppWithNodePackages" -o "D:\FunctionAppWithNodePackages" --functionApp --sitePath "D:\FunctionAppWithNodePackages\functionSrc"
on my local machine, the output is

@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off

:: ----------------------
:: KUDU Deployment Script
:: Version: 1.0.14
:: ----------------------

:: Prerequisites
:: -------------

:: Verify node.js installed
where node 2>nul >nul
IF %ERRORLEVEL% NEQ 0 (
echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
goto error
)

:: Setup
:: -----

setlocal enabledelayedexpansion

SET ARTIFACTS=%~dp0%..\artifacts

IF NOT DEFINED DEPLOYMENT_SOURCE (
SET DEPLOYMENT_SOURCE=%~dp0%.
)

IF NOT DEFINED DEPLOYMENT_TARGET (
SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
)

IF NOT DEFINED NEXT_MANIFEST_PATH (
SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest

IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
)
)

IF NOT DEFINED KUDU_SYNC_CMD (
:: Install kudu sync
echo Installing Kudu Sync
call npm install kudusync -g --silent
IF !ERRORLEVEL! NEQ 0 goto error

:: Locally just running "kuduSync" would also work
SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Deployment
:: ----------

echo Handling function App deployment.

if "%SCM_USE_FUNCPACK%" == "1" (
call :DeployWithFuncPack
) else (
call :DeployWithoutFuncPack
)

goto end

:DeployWithFuncPack
setlocal

echo Using funcpack to optimize cold start

:: 1. Copy to local storage
echo Copying repository files to local storage
xcopy "%DEPLOYMENT_SOURCE%\functionSrc" "%DEPLOYMENT_TEMP%" /seyiq
IF !ERRORLEVEL! NEQ 0 goto error

:: 2. Restore npm
call :RestoreNpmPackages "%DEPLOYMENT_TEMP%"

:: 3. FuncPack
pushd "%DEPLOYMENT_TEMP%"
call funcpack pack .
IF !ERRORLEVEL! NEQ 0 goto error
popd

:: 4. KuduSync
call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_TEMP%" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd;node_modules"
IF !ERRORLEVEL! NEQ 0 goto error

exit /b %ERRORLEVEL%

:DeployWithoutFuncPack
setlocal

echo Not using funcpack because SCM_USE_FUNCPACK is not set to 1

:: 1. KuduSync
IF /I "%IN_PLACE_DEPLOYMENT%" NEQ "1" (
call :ExecuteCmd "%KUDU_SYNC_CMD%" -v 50 -f "%DEPLOYMENT_SOURCE%\functionSrc" -t "%DEPLOYMENT_TARGET%" -n "%NEXT_MANIFEST_PATH%" -p "%PREVIOUS_MANIFEST_PATH%" -i ".git;.hg;.deployment;deploy.cmd"
IF !ERRORLEVEL! NEQ 0 goto error
)

:: 2. Restore npm
call :RestoreNpmPackages "%DEPLOYMENT_TARGET%"

exit /b %ERRORLEVEL%

:RestoreNpmPackages
setlocal

echo Restoring npm packages in %1

IF EXIST "%1\package.json" (
pushd "%1"
call npm install --production
IF !ERRORLEVEL! NEQ 0 goto error
popd
)

FOR /F "tokens=*" %%i IN ('DIR /B %1 /A:D') DO (
IF EXIST "%1%%i\package.json" (
pushd "%1%%i"
call npm install --production
IF !ERRORLEVEL! NEQ 0 goto error
popd
)
)

exit /b %ERRORLEVEL%

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
goto end

:: Execute command routine that will echo out when error
:ExecuteCmd
setlocal
set CMD=%*
call %CMD%
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%CMD%
exit /b %ERRORLEVEL%

:error
endlocal
echo An error has occurred during web site deployment.
call :exitSetErrorLevel
call :exitFromFunction 2>nul

:exitSetErrorLevel
exit /b 1

:exitFromFunction
()

:end
endlocal
echo Finished successfully.

if you are using kudu, this script is invoked for you.
if my guess is wrong, please provide more detail about how you use this template. thanks

Your guess was indeed correct. I was linked directly to the template and had assumed I would need to rename the file myself, especially since I didn't find further documentation in the readme for the project, perhaps this would be a good addition?

I just now installed kuduscript from npm, which produces a sligthly different output from what you posted; I assume this is because the npm package has not been updated yet?

EDIT: I also ran the command using the repository, which generated the script you posted. This script also runs successfully on the functionApp environment.

So aside from the documentation suggestion, this issue can be closed.

I just updated the package on npm: 1.0.15