What i am trying to do?
Build one YAML file that builds and deploys service as a webjob inside webjobs location in appservice's webjobs location.
I have this one YAML code that builds and deploys a console application of a worker service as a Azure Webjob in the appservice.
The build is succeeded and deployment is also succeeding, however the webjob is not being placed in the right location.
I want this to be deployed inside site-> jobs ->continuous->webjob name, but it gets deployed into site->wwwroot->webjob name
trigger:
branches:
include:
- main
paths
include:
- MyTestJobJob/MyTestJobService.cs
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
devWebAppName: 'MyTestJobJobDev'
resourceGroupName: 'MyRG'
webJobName: 'MyTestJobJob'
stages:
- stage: Build
jobs:
- job: Build
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '8.x'
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
projects: 'MyTestJobJob/MyTestJobJob.csproj'
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/publish_output/App_Data/jobs/continuous/$(webJobName)'
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
projects: 'MyTestJobJob/MyTestJobJob.csproj'
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/publish_output'
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/MyTestJobJob.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/MyTestJobJob.zip'
ArtifactName: 'drop'
publishLocation: 'Container'
- stage: DeployToDev
dependsOn: Build
jobs:
- deployment: DeployToDev
environment: 'Dev'
strategy:
runOnce:
deploy:
steps:
- download: current
artifact: drop
- task: AzureWebApp@1
inputs:
azureSubscription: 'MyAZSubscription' # Pushes changes to the webjob
appName: '$(devWebAppName)'
package: '$(Pipeline.Workspace)/drop/MyTestJobJob.zip'
resourceGroupName: '$(resourceGroupName)'
webJobName: '$(webJobName)'
webJobType: 'Continuous'
publishWebProjects: false
I think the change needs to happen in this line, but i am not sure, what needs to be altered to push into the right azure webjob location
arguments: '--configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/publish_output/App_Data/jobs/continuous/$(webJobName)'
If i manually add a new webjob inside azure webjobs of appservice and attach the artifact zip file, the webjob runs which i am trying to automate.
To deploy the webjob into target location, you need to make sure the zip file(MyTestJobJob.zip) in artifact has correct folder structure, App_Data/jobs/continuous
for continuous
type.
The artifact sample on my side for your reference:
For your yaml artifact result, there will be extra publish_output
in the path, and extra files in the zip.
To fix the zip file strucutre, please change the location $(Build.ArtifactStagingDirectory)
in publish argument to $(Build.BinariesDirectory)
, and fix the root folder for ArchiveFiles@2 task.
Sample as below:
trigger:
branches:
include:
- main
paths:
include:
- MyTestJobJob/MyTestJobService.cs
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
devWebAppName: 'MyTestJobJobDev'
resourceGroupName: 'MyRG'
webJobName: 'MyTestJobJob'
stages:
- stage: Build
jobs:
- job: Build
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '8.x'
installationPath: $(Agent.ToolsDirectory)/dotnet
- task: DotNetCoreCLI@2
inputs:
command: 'restore'
projects: '**/*.csproj'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
projects: 'MyTestJobJob/MyTestJobJob.csproj'
arguments: '--configuration $(buildConfiguration) --output $(Build.BinariesDirectory)/publish_output/App_Data/jobs/continuous/$(webJobName)'
publishWebProjects: false
modifyOutputPath: false
zipAfterPublish: false
# - task: DotNetCoreCLI@2
# inputs:
# command: 'publish'
# projects: 'MyTestJobJob/MyTestJobJob.csproj'
# arguments: '--configuration $(buildConfiguration) --output $(Build.BinariesDirectory)/publish_output'
# publishWebProjects: false
# modifyOutputPath: false
# zipAfterPublish: false
- task: ArchiveFiles@2
inputs:
rootFolderOrFile: '$(Build.BinariesDirectory)/publish_output'
includeRootFolder: false
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/MyTestJobJob.zip'
replaceExistingArchive: true
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
I commented the 2nd publish task, add it back if it's needed for you.
In addition, for AzureWebApp@1
deployment task, it doesn't have parameters webJobName
, webJobType
, publishWebProjects
, but appType
is needed.
- task: AzureWebApp@1
inputs:
azureSubscription: 'MyAZSubscription'
appType: 'webApp'
appName: '$(devWebAppName)'
package: '$(Pipeline.Workspace)/drop/MyTestJobJob.zip'
deploymentMethod: 'auto'
Please check my another answer in similar ticket for your reference.