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)"
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)
- Add Azure App Service Deploy task by specifing the Package or folder option as
$(Build.ArtifactStagingDirectory)**$(buildproj)
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…