我正在尝试部署一个 react 网络应用程序。这是我当前的 yaml 文件。我一直在关注this教程。
trigger:
- master
pool:
vmImage: 'ubuntu-latest'
variables:
azureSubscription: <myServiceConnection>
appName: <myAppName>
steps:
- task: NodeTool@0
inputs:
versionSpec: '10.x'
displayName: 'Install Node.js'
#so this calls the build object in package.json. Theoretically creates a /build/ directory
- script: |
npm install
npm run build
displayName: 'npm install and build'
#this should copy contents of build into artifactstagingdirectory.
- task: CopyFiles@2
inputs:
Contents: 'build/**' # Pull the build directory (React)
TargetFolder: '$(Build.ArtifactStagingDirectory)'
- task: PublishBuildArtifacts@1
inputs:
pathtoPublish: $(Build.ArtifactStagingDirectory) # dist or build files
ArtifactName: 'www' # output artifact named www
- task: AzureWebApp@1
inputs:
azureSubscription: <myServiceConnection>
appName: <myAppName>
appType: webAppLinux
package: $(Build.ArtifactStagingDirectory)/**/www/build
customWebConfig: '-handler iisnode -NodeStartFile server.js -appType node'
基本上,问题是我不明白 PublishBuildArtifact 任务在哪里发布文件,因此我不知道将 AzureWebApp 的包指向哪里。
所以我打开了system.debug,并得到了以下信息
- npm install build 使用以下目录:
/home/vsts/work/1/s
- 复制文件复制构建文件夹。因此,它会从
/home/vsts/work/1/s/build
转到/home/vsts/work/1/a/build
。所以这意味着artifactstagingdirectory是/home/vsts/work/1/a
- 发布构建工件采用artifactstagingdirectory并将其发布到某个文件夹
www/build
。提供以下输出:将 '/home/vsts/work/1/a' 上传到文件容器:'#/8995596/www'
- 当前的 AzureWebApp 任务正在
/home/vsts/work/1/a/**/www/build
中查找
所以我认为它应该是正确的目录。但是,它没有在步骤 3 中提供完整路径。所以看起来我错了。这个 www 文件夹是在哪里创建的?
此外,由于构建/发布 React 应用程序似乎不会创建 zip 文件,我是否只需将其指向构建文件夹或 www 文件夹?
最佳答案
尝试一下 **/wwwroot/ 而不是 **/www/
查看 Microsoft 的以下博客,其中概述了部署详细信息。
https://learn.microsoft.com/en-us/azure/app-service/faq-deployment
关于azure - 我应该将 AzureWebApp 任务指向什么路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63201301/