Azure Git 支持的持续部署的正确部署脚本

Correct deployment script for Azure Git backed continuous Deployment

我有一个 ASP.Net 4.5 MVC 应用程序,它使用 Angular 1.5。 JS 代码是 Typescript,post 构建操作构建 js 代码并将其部署到我的应用程序引用的文件夹。

我的 Azure Web 应用程序上有一个插槽,它支持我的 gitlab 存储库。提交 repo,触发部署,但是 post 部署构建似乎经常在 bower/npm 或 typings 库更新时出现问题(通过 kudu 控制台手动清除文件夹解决)。有人有一个 deploy.cmd 脚本的例子吗,它相当于

在管道中的正确位置,以便正确部署文件。 我想从头开始使用一个新插槽,为了让现有插槽在过去工作,我必须手动安装打字,例如 "npm install typings --global" 才能使构建工作而不会出现打字错误。

更新下面的输出 我猜下面的错误是由于 azure 运行 typescript 1.6 编译器对需要 typescript > 1.6 的参考文件造成的。 我的 csproj 有 <TypeScriptToolsVersion>2.0</TypeScriptToolsVersion> (我从编译输出中删除了我的文件,但 _all.d.ts 文件确实引用了下面的错误文件

  CompileTypeScript:
  D:\Program Files (x86)\Microsoft SDKs\TypeScript.6\tsc.exe  --sourcemap --target ES5 --noEmitOnError "REMOVED MY TYPESCRIPTFILES" "D:\home\site\repository\mymvcproject\app\src\_all.d.ts"
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1824,32): error TS1110: Build: Type expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1824,50): error TS1005: Build: ']' expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1824,58): error TS1005: Build: ',' expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1824,59): error TS1136: Build: Property assignment expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
D:\home\site\repository\mymvcproject\typings\globals\angular\index.d.ts(1941,1): error TS1128: Build: Declaration or statement expected. [D:\home\site\repository\mymvcproject\mymvcproject.csproj]
Done Building Project "D:\home\site\repository\mymvcproject\mymvcproject.csproj" (Build;pipelinePreDeployCopyAllFilesToOneFolder target(s)) -- FAILED.

最终更新 在 typescript 团队最终生成了一个可以安装在 Azure 上的 typescript 2.* 版本之后,Kudu 团队就部署了它。现在整个过程都有效了!下面关于使用

的注释
"preinstall": "npm install typescript -g && npm install typings -g"

是解决方案的另一部分!

根据您的要求,您可以按照以下步骤来达到您的目的。

创建部署脚本

您可以登录KUDU工具(https://.scm.azurewebsites.net/),点击"Tool" > "Download deployment script"。此外,您可以利用 azure-cli 生成脚本。关于如何通过azure-cli生成部署脚本的更多细节,你可以参考这个tutorial.

自定义部署脚本

要使用 NPM 管理您的包,您可以在 package.json 文件中添加以下脚本。

"scripts":{
    "preinstall": "npm install typescript -g && npm install typings -g"
 }

然后,您需要将以下脚本添加到deploy.cmd文件中。

IF EXIST "%DEPLOYMENT_SOURCE%\package.json" (
  pushd "%DEPLOYMENT_SOURCE%"
  echo installing npm package
  call :ExecuteCmd npm install --production
  IF !ERRORLEVEL! NEQ 0 goto error
  popd
)

或者您可以添加以下脚本,直接通过命令行安装 typescript 和 typings。

echo Installing typescript and typings
call npm install typescript -g && npm install typings -g
IF !ERRORLEVEL! NEQ 0 goto error

注意:.deployment,deploy.cmd 文件需要放在解决方案的根目录中。详情可以参考这个sample项目。