我正在尝试为应用程序服务部署 WebJob,以及应用程序服务本身。但我发现没有一个方法有效。有关该主题的所有在线信息似乎都已过时(我找不到任何 Microsoft 文档)。
其他一切正常 - 我已经验证该工件在正确的位置具有所有正确的文件。应用程序服务本身上传得很好。该问题纯粹是 WebJob 的问题。 (为了清晰和安全起见,我对此进行了编辑)
trigger:
- development
pool:
vmImage: windows-latest
variables:
BuildConfiguration: 'Release'
AzureSubscription: 'Subscription'
stages:
- stage: Build
jobs:
- job: BuildJob
steps:
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/*.sln'
feedsToUse: 'select'
- task: VSBuild@1
inputs:
solution: '**/API.csproj'
configuration: '$(BuildConfiguration)'
msbuildArgs: '/p:OutputPath=$(Build.ArtifactStagingDirectory)/APIOutput'
platform: 'any cpu'
- task: VSBuild@1
inputs:
solution: '**/WebJob.csproj'
configuration: '$(BuildConfiguration)'
msbuildArgs: '/p:OutputPath=$(Build.ArtifactStagingDirectory)/WebJobOutput'
platform: 'any cpu'
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'drop'
publishLocation: 'Container'
- stage: Deploy
dependsOn: Build
jobs:
- job: DeployJob
steps:
- download: current
artifact: 'drop'
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '$(AzureSubscription)'
appType: 'webApp'
WebAppName: 'WebAppName'
packageForLinux: '$(Pipeline.Workspace)/drop/APIOutput'
- task: AzureRmWebAppDeployment@4
inputs:
ConnectionType: 'AzureRM'
azureSubscription: '$(AzureSubscription)'
appType: 'webApp'
WebAppName: 'WebAppName'
packageForLinux: '$(Pipeline.Workspace)/drop/WebJobOutput'
我引用了 Rahul Nath 的这篇博客,并使用 Azure DevOps 构建和发布管道一起部署了 Azure Web App + Azure WebJob 将其部署在单个构建 YAML 管道中
参考我的 Github 存储库,引用自 Rahul Nath 的存储库,使用我自己的 Azure YAML 管道在单个 yaml 管道中部署 Web 应用程序 + WebJob。
我将此存储库推送到 Azure DevOps 存储库中,然后构建了我的 Azure Web 应用程序 + Azure WebJob 解决方案,如下所示:-
我的构建 YAML 管道:-
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/WebJobExample.WebJob.csproj'
arguments: '--output $(Build.BinariesDirectory)/publish_output/App_Data/jobs/continuous/YoutubeWebJob'
zipAfterPublish: false
modifyOutputPath: false
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--output $(Build.BinariesDirectory)/publish_output'
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'
输出:-
现在,在发布管道中使用 build Artifact。
在发布管道中选择上面的构建工件:-
在阶段中选择部署 Azure 应用服务任务并添加所需的配置:-
我创建了一个 .Net 6.0 Windows Azure Web 应用程序,并在我的任务中选择了它,如下所示:-
在“部署 Azure 应用服务”步骤中,在“文件转换”步骤中添加了
**/appsettings.json
,并保持其余设置不变:-
使用 AzureWebJobStorage 连接字符串添加了一个变量,这是我的存储帐户的连接字符串:-
现在,我保存了管道并创建了一个版本:-
发布成功,Azure Web App + Azure Web Job 部署成功:-
输出:-
如果您想在单个 YAML 管道中运行此,请参阅下面的代码:-
trigger:
- master
pool:
vmImage: 'windows-latest'
steps:
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '**/*.csproj'
arguments: '--configuration Release'
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: false
projects: '**/WebJobExample.WebJob.csproj'
arguments: '--output $(Build.BinariesDirectory)/publish_output/App_Data/jobs/continuous/YoutubeWebJob'
zipAfterPublish: false
modifyOutputPath: false
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--output $(Build.BinariesDirectory)/publish_output'
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: 'xx subscription (xxxxxxxxxxxe97cb2a7)'
appType: 'webApp'
WebAppName: 'valleywebappjob'
packageForLinux: '$(Agent.BuildDirectory)/**/*.zip'
WebConfigParameters: '**/appsettings.json'
输出:-