Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

azure devops - Multiple Jobs Deployment in Visual Studio Team Services

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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. Add a variable (such as buildporj with default value none) to record the changed webJob project package.

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

3. Add Visual studio Build task with the MSBuild arguments:

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

enter image description here

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. Add Azure App Service Deploy task by specifing the Package or folder option as $(Build.ArtifactStagingDirectory)**$(buildproj).

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...