Azure WebJobs CD ereasing wwwroot content

120 Views Asked by At

I'm publishing 2 web jobs to the respective paths:

Azure AppService Configuration

But, every time, the content inside site\wwwroot is erased, and I have an API project published there, so, every time I need to republish the API after.

I can't find a solution anywhere about this, why is this happening?

This is my web jobs CD:

WebJob Cd Tasks

I was expecting having to republish my API every time I publish my web job.

2

There are 2 best solutions below

1
Miao Tian-MSFT On BEST ANSWER

I can reproduce the issue when I tried to deploy files to the Virtual application path, and I found the site\wwwroot folder will be back to the old last version.

Workaround

If I change the task version from AzureRmWebAppDeployment@4 to AzureRmWebAppDeployment@3, it works and will not make change to the files in the site\wwwroot folder. I also find a known issue here for your reference.

enter image description here

3
SiddheshDesai On

In order for Webjobs to deploy properly, You need to build them together in the app folder and then Publish the build artifact to the Azure Web App service.

Refer my SO answer here.

My Azure DevOps yaml pipeline:-

trigger:
- master

pool:
  vmImage: 'windows-latest'

jobs:
- job: BuildAndDeployWebJobs
  displayName: 'Build and Deploy Web Jobs'

  steps:
  - task: UseDotNet@2
    inputs:
      packageType: 'sdk'
      version: '3.x'
      installationPath: $(Agent.ToolsDirectory)/dotnet

  - task: DotNetCoreCLI@2
    inputs:
      command: 'build'
      projects: '**/*.csproj'
      arguments: '--configuration Release'

  - task: DotNetCoreCLI@2
    inputs:
      command: 'publish'
      publishWebProjects: false
      projects: '**/Webjob1.csproj'
      arguments: '--output $(Build.BinariesDirectory)/publish_output/App_Data/jobs/continuous/WebJob1'
      zipAfterPublish: false
      modifyOutputPath: false

  - task: DotNetCoreCLI@2
    inputs:
      command: 'publish'
      publishWebProjects: true
      projects: '**/WebJobExample.WebJob.csproj'
      arguments: '--output $(Build.BinariesDirectory)/publish_output/App_Data/jobs/continuous/WebJobExample'
      zipAfterPublish: false
      modifyOutputPath: false

  - task: ArchiveFiles@2
    inputs:
      rootFolderOrFile: '$(Build.BinariesDirectory)/publish_output'
      includeRootFolder: false
      archiveType: 'zip'
      archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
      replaceExistingArchive: true

  - task: PublishBuildArtifacts@1
    inputs:
      PathtoPublish: '$(Build.ArtifactStagingDirectory)'
      ArtifactName: 'drop'
      publishLocation: 'Container'

  - task: AzureRmWebAppDeployment@4
    inputs:
      ConnectionType: 'AzureRM'
      azureSubscription: 'xxx subscription (xxxxxxxxx97cb2a7)'
      appType: 'webApp'
      WebAppName: 'siliconwebapp098'
      packageForLinux: '$(Agent.BuildDirectory)/**/*.zip'
      JSONFiles: '**/appsettings.json'

I have build both the WebJobs separately and then published the build artifact to the Azure Web app above.

Output:-

enter image description here

enter image description here

Release pipeline:-

enter image description here

enter image description here

enter image description here