Visual Studio Team Services 中的多个作业部署 [英] Multiple Jobs Deployment in Visual Studio Team Services

查看:19
本文介绍了Visual Studio Team Services 中的多个作业部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个项目的 VS 解决方案,每个项目都是一个独立的 WebJob,我托管在单个 AppServices 中.我正在尝试将其自动化为持续部署.在已更改的解决方案中仅部署作业的最佳策略是什么?有没有办法找出作为合并到 CI 的一部分而更改的项目?我们正在使用 git,这个解决方案位于一个存储库中.我们正在为项目使用 azure-webjobsdk.

I have a VS solution with multiple projects, each project is an independent WebJob which I am hosting in a Single AppServices. I am trying to automate this to Continuous deployment.What would be the best strategy to deploy only job in the solution which is changed? Is there a way to find out the project which is changed as part of the merge to CI? We are using git and this solution is in a single repository. We are using azure-webjobsdk for the projects.

推荐答案

您可以按照以下步骤部署唯一更改的 webjob:

You can follow below steps to deploy the only changed webjob:

假设您的文件结构如下:

Assume your file structure as below:

Git root
   |___WebJob1
          |___WebJob1.sln
          |___webJob1
                 |___WebJob1.csproj
          |___WebJob2
                 |___WebJob2.csproj
          |___ …
          |___WebJobn
                 |___WebJobn.csproj

1.添加一个变量(如buildporj,默认值为none)记录修改后的webJob项目包.

1. Add a variable (such as buildporj with default value none) to record the changed webJob project package.

2.为 WebJob1/WebJob1.sln 添加 NuGet 还原任务.

2. Add NuGet restore task for the WebJob1/WebJob1.sln.

3.使用 MSBuild 参数添加 Visual Studio Build 任务:

/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.BinariesDirectory)\"

4.添加 PowerShell Task 以检测哪个 WebJob 项目更改并将包从 $(Build.BinariesDirectory) 复制到 $(Build.ArtifactStagingDirectory) 中,如下所示:

4. Add PowerShell Task to detect which WebJob project changed and copy the package from $(Build.BinariesDirectory) to $(Build.ArtifactStagingDirectory) by the script as below:

$files=$(git diff HEAD HEAD~ --name-only)
echo "changed files: $files"
for ($i=0;$i -lt $files.Length; $i++)
{
  $file=$files[$i] -split '/'
  $files[$i]=$file[1]
}
$uni=$files | Get-Unique

$uni=@($uni | Where-Object {$_ -notmatch ".sln"})
echo "You changed the project (if more than one projects were changed, only deploy the first one): $uni"
$proj=$uni[0]+".zip"
Write-Host "##vso[task.setvariable variable=buildproj;]$proj"
Copy-Item $(Build.BinariesDirectory)$proj $(Build.ArtifactStagingDirectory)

  1. 添加 Azure 应用服务部署任务,方法是将包或文件夹选项指定为 $(Build.ArtifactStagingDirectory)**$(buildproj).
  1. Add Azure App Service Deploy task by specifing the Package or folder option as $(Build.ArtifactStagingDirectory)**$(buildproj).

这篇关于Visual Studio Team Services 中的多个作业部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆