I am attempting to set up some Azure pipelines to build and deploy some WebJobs. The build and deployment seem to work fine. Until I run it a second time. We have about 20 WebJobs running on the same Azure Web App. These perform background tasks for our application.
Scenario:
I searched quite a bit and I am unable to figure out this behavior. Something cached, some cleanup step? I can't figure out why one would step on the other. Any ideas would be appreciated.
The YML file below is the same for both pipelines, the only difference is the jobName.
Edit: For clarity..
When WebJob1 deploys, the files are properly deployed to c:\home\site\wwwroot\app_data\Jobs\Triggered\WebJob1.
When WebJob2 deploys, the files are properly deployed to c:\home\site\wwwroot\app_data\Jobs\Triggered\WebJob2.
..but when WebJob2 deploys, it also deletes the files in the WebJob1 directory
trigger:
- DEV
pool:
name: Dev Pipeline Pool
variables:
- name: jobName
value: TestWebJob
- name: jobType
value: Triggered
- name: serviceConnectionToDeployTo1
value: devApp-sc
- name: appServiceName
value: devApp
resources:
repositories:
- repository: WebJobLib
type: git
name: WebJobLib
ref: master
steps:
- checkout: self
- checkout: WebJobLib
- task: DotNetCoreCLI@2
displayName: Run dotnet build
inputs:
command: build
projects: '**/*.csproj'
arguments: --configuration release
- task: DotNetCoreCLI@2
displayName: Run dotnet publish
inputs:
command: publish
publishWebProjects: false
projects: '**/*.csproj'
arguments: --output $(Build.SourcesDirectory)/publish_output/app_data/Jobs/$(jobType)/$(jobName)
zipAfterPublish: false
modifyOutputPath: false
- task: ArchiveFiles@2
displayName: Archive published output
inputs:
rootFolderOrFile: $(Build.SourcesDirectory)/publish_output
includeRootFolder: false
archiveType: zip
archiveFile: $(System.DefaultWorkingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
verbose: true
- task: AzureWebApp@1
displayName: Azure Web App Deploy
inputs:
azureSubscription: $(serviceConnectionToDeployTo1)
appType: webApp
appName: $(appServiceName)
package: $(System.DefaultWorkingDirectory)/$(Build.BuildId).zip
deploymentMethod: auto
You need to build your webjobs
separately in the app folder
and publish its artifact
in the Azure Web App
like below:-
My build pipeline:-
I have built the 2 Webjobs separately
with DotNetCoreCl@2
command:-
- 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
Complete 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: 'subscription (xxxxxxxxxe97xxxxx2a7)'
appType: 'webApp'
WebAppName: 'valleywebapp92'
packageForLinux: '$(Agent.BuildDirectory)/**/*.zip'
JSONFiles: '**/appsettings.json'
Output:-