Skip to content

Commit b87a54f

Browse files
committed
Add kudu deployment script
1 parent 526a0a5 commit b87a54f

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

.deployment

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[config]
2+
command = deploy.cmd

deploy.cmd

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
@if "%SCM_TRACE_LEVEL%" NEQ "4" @echo off
2+
3+
:: ----------------------
4+
:: KUDU Deployment Script
5+
:: Version: 1.0.17
6+
:: ----------------------
7+
8+
:: Prerequisites
9+
:: -------------
10+
11+
:: Verify node.js installed
12+
where node 2>nul >nul
13+
IF %ERRORLEVEL% NEQ 0 (
14+
echo Missing node.js executable, please install node.js, if already installed make sure it can be reached from current environment.
15+
goto error
16+
)
17+
18+
:: Setup
19+
:: -----
20+
21+
setlocal enabledelayedexpansion
22+
23+
SET ARTIFACTS=%~dp0%..\artifacts
24+
25+
IF NOT DEFINED DEPLOYMENT_SOURCE (
26+
SET DEPLOYMENT_SOURCE=%~dp0%.
27+
)
28+
29+
IF NOT DEFINED DEPLOYMENT_TARGET (
30+
SET DEPLOYMENT_TARGET=%ARTIFACTS%\wwwroot
31+
)
32+
33+
IF NOT DEFINED NEXT_MANIFEST_PATH (
34+
SET NEXT_MANIFEST_PATH=%ARTIFACTS%\manifest
35+
36+
IF NOT DEFINED PREVIOUS_MANIFEST_PATH (
37+
SET PREVIOUS_MANIFEST_PATH=%ARTIFACTS%\manifest
38+
)
39+
)
40+
41+
IF NOT DEFINED KUDU_SYNC_CMD (
42+
:: Install kudu sync
43+
echo Installing Kudu Sync
44+
call npm install kudusync -g --silent
45+
IF !ERRORLEVEL! NEQ 0 goto error
46+
47+
:: Locally just running "kuduSync" would also work
48+
SET KUDU_SYNC_CMD=%appdata%\npm\kuduSync.cmd
49+
)
50+
IF NOT DEFINED DEPLOYMENT_TEMP (
51+
SET DEPLOYMENT_TEMP=%temp%\___deployTemp%random%
52+
SET CLEAN_LOCAL_DEPLOYMENT_TEMP=true
53+
)
54+
55+
IF DEFINED CLEAN_LOCAL_DEPLOYMENT_TEMP (
56+
IF EXIST "%DEPLOYMENT_TEMP%" rd /s /q "%DEPLOYMENT_TEMP%"
57+
mkdir "%DEPLOYMENT_TEMP%"
58+
)
59+
60+
IF DEFINED MSBUILD_PATH goto MsbuildPathDefined
61+
SET MSBUILD_PATH=%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe
62+
:MsbuildPathDefined
63+
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
64+
:: Deployment
65+
:: ----------
66+
67+
echo Handling ASP.NET Core Web Application deployment.
68+
69+
:: 1. Restore nuget packages
70+
call :ExecuteCmd dotnet restore "%DEPLOYMENT_SOURCE%\gitattributes.sln"
71+
IF !ERRORLEVEL! NEQ 0 goto error
72+
73+
:: 2. Build and publish
74+
call :ExecuteCmd dotnet publish "%DEPLOYMENT_SOURCE%\src\gitattributes.csproj" --output "%DEPLOYMENT_TEMP%" --configuration Release
75+
IF !ERRORLEVEL! NEQ 0 goto error
76+
77+
:: 3. KuduSync
78+
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"
79+
IF !ERRORLEVEL! NEQ 0 goto error
80+
81+
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
82+
goto end
83+
84+
:: Execute command routine that will echo out when error
85+
:ExecuteCmd
86+
setlocal
87+
set _CMD_=%*
88+
call %_CMD_%
89+
if "%ERRORLEVEL%" NEQ "0" echo Failed exitCode=%ERRORLEVEL%, command=%_CMD_%
90+
exit /b %ERRORLEVEL%
91+
92+
:error
93+
endlocal
94+
echo An error has occurred during web site deployment.
95+
call :exitSetErrorLevel
96+
call :exitFromFunction 2>nul
97+
98+
:exitSetErrorLevel
99+
exit /b 1
100+
101+
:exitFromFunction
102+
()
103+
104+
:end
105+
endlocal
106+
echo Finished successfully.

gitattributes.sln

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ VisualStudioVersion = 15.0.27703.2018
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CFCC326F-2A99-4985-8612-50C8DB63DBA3}"
66
ProjectSection(SolutionItems) = preProject
7+
.deployment = .deployment
8+
deploy.cmd = deploy.cmd
79
NuGet.Config = NuGet.Config
810
README.md = README.md
911
EndProjectSection
File renamed without changes.

0 commit comments

Comments
 (0)