Multiple Jobs Deployment in Visual Studio Team Services

后端 未结 2 1080
予麋鹿
予麋鹿 2020-12-22 04:08

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 dep

相关标签:
2条回答
  • 2020-12-22 04:20

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

    0 讨论(0)
  • 2020-12-22 04:34

    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:-

    1. Visual Studio Build (Solution: ***.sln, MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)\")

    2. 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

    1. Azure App Service Deploy
    2. Select your Azure Subscription and App Service name;
    3. 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.

    0 讨论(0)
提交回复
热议问题