I have a dotnet6 project which I want to deploy on a AppService in Azure. I am using Auzre Devops for my CICD and there I'm using a Yaml file for build and later deployment. I have also some WebJobs that I want to deploy on the same AppService in the same slot. The build process of my solution will provide a zip file with some files:
1- zip file 2- Parameters.xml 3- SetParameters.xml 4- readme.txt 5- and a deploy.cmd file which is a Batch file
This is the task for building a solution:
- task: VSBuild@1
inputs:
solution: 'Mydea/Mydea.sln'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\yourProject.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
clean: true
Later in CD I use another command to deploy my zip file into the Azure like this:
- task: AzureRmWebAppDeployment@4
displayName: 'Deploy WebApp'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'xxxx'
appType: 'webApp'
WebAppName: 'xxx'
deployToSlotOrASE: true
ResourceGroupName: 'xxxx'
SlotName: 'Test'
packageForLinux: '$(pipeline.workspace)/drop/WebApp.zip'
JSONFiles: '**/appsettings.json'
until here is everything fine.
But if I want to deploy some WebJob, it is different. I will not have a zip file with some batch, the only thing that I need here is a zip file which directing to the correct path: App_Data/jobs/triggered/yourproject
later in the CD you need to call the same task in order to deploy your Webjobs.
Problem: I can create 2 seperate zip file in the same artifact and later in CD, I need to call the deploy task. But the deploy task only can get one zip file. If you calling the deploy task 2 times it will override it. that means you can have only your project deployed or your webjobs.
My idea was to combine the two zip files in the CI like this:
- task: VSBuild@1
inputs:
solution: 'xxx/xxx.sln'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactstagingdirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'
clean: true
- task: ExtractFiles@1
inputs:
archiveFilePatterns: '$(build.artifactstagingdirectory)\WebApp.zip'
destinationFolder: '$(Build.BinariesDirectory)/root'
cleanDestinationFolder: true
overwriteExistingFiles: true
- task: DotNetCoreCLI@2
displayName: 'publish Webjob Daily'
inputs:
command: 'publish'
publishWebProjects: false
projects: 'xxx/xxx.Webjob.Daily/xxx.Webjob.Daily.csproj'
arguments: '--output $(Build.BinariesDirectory)/root/App_Data/jobs/triggered/WebjobDaily'
zipAfterPublish: false
modifyOutputPath: false
- task: ArchiveFiles@2
displayName: 'Zip solution'
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)/root'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/WebApp.zip'
replaceExistingArchive: true
- task: PublishPipelineArtifact@1
displayName: Publish drop Artifact
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)'
artifact: 'drop'
publishLocation: 'pipeline'
As you can see in this tasks, I combine the 2 zip files into one zip file. notice that the zip file for the main solution has also some extra files with one batch file.
I tried to deploy this zip file in CD, the main project was successfully deployed but not the WebJobs.
If I deploy only the main project or only the WebJobs, it will be successfully done. but I need to deploy both of them togehter.
Now for me the last way is to create for my project another slot in the AppService. and deploy the main project on one Slot and the WebJobs on the other and this will work. But this is not a clean solution. I like to have them both in the same Slot.
I found the solution. In the deployment you should have two separate zip files one for your WebApp and the other for your WebJobs, exactly like the code in my question.
In the deployment you should call the AzureRmWebAppDeployment@4
task two times, first for your WebApp and after that for your WebJobs.
But...
in order that the second task doesn't override the first task you should alter 2 other parameters; enableCustomDeployment
to true and ExcludeFilesFromAppDataFlag
to false.
- task: AzureRmWebAppDeployment@4
displayName: 'Deploy WebApp'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'xxx'
appType: 'webApp'
WebAppName: 'xxx'
deployToSlotOrASE: true
ResourceGroupName: 'xxx'
SlotName: 'Test'
packageForLinux: '$(pipeline.workspace)/drop/WebApp.zip'
JSONFiles: '**/appsettings.json'
- task: AzureRmWebAppDeployment@4
displayName: 'Deploy Webjobs'
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'xxx'
appType: 'webApp'
WebAppName: 'xxx'
deployToSlotOrASE: true
ResourceGroupName: 'xxx'
SlotName: 'Test'
packageForLinux: '$(pipeline.workspace)/drop/Webjobs.zip'
JSONFiles: '**/appsettings.json'
enableCustomDeployment: true
ExcludeFilesFromAppDataFlag: false