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.

- 1,373
- 6
- 22
- 45
-
What's your VSTS build definition now? Do you use Azure App Service Deploy task to deploy web jobs now? – Marina Liu Dec 08 '17 at 05:33
-
I don't have one now, can I deploy multiple webjobs from a single solution with App Service Deploy task. – Shiju Samuel Dec 08 '17 at 06:01
-
No, you can only deploy one webjob by a App Service Deploy task. I added an answer for deployging the changed webjob project, you can have a try. – Marina Liu Dec 08 '17 at 09:11
-
facing issue like - deploying multiple webjobs using seperate app service deploy task replacing all the web jobs and can only see last one - please help – user27178 May 26 '20 at 08:34
2 Answers
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)
.

- 36,876
- 5
- 61
- 74
You can have different WebJobs project(WebJob1.csproj, WebJob2.csproj) in a single solution and you can deploy using single build and release pipeline. All you need to do is :-
In your build solution step define:-
Visual Studio Build (Solution: ***.sln, MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\")
Publish Build Artifacts (Path to Publish: $(build.artifactstagingdirectory); Artifact Name: drop; Artifact Type: Server)
Create a release definition for this build definition and add a task
- Azure App Service Deploy
- Select your Azure Subscription and App Service name;
- Select your Package or Folder: $(System.DefaultWorkingDirectory)**\WebJob1.zip
You can similary create another Azure App Service Deploy task for WebJob2.zip and deploy as many webjobs you want through a single build and release pipeline.
-
1Deploying multiple jobs replacing all existing and last one is only present. help – user27178 May 26 '20 at 08:36
-
1