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

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

问题描述

我有一个包含多个项目的VS解决方案,每个项目都是一个独立的WebJob,我将其托管在Single 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.添加变量(例如默认值为nonebuildporj)来记录更改后的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任务,以检测哪个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)

    通过将Package或Folder选项指定为$(Build.ArtifactStagingDirectory)\**\$(buildproj)
  1. 添加Azure App Service部署任务.
  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天全站免登陆