gpt4 book ai didi

reactjs - Azure DevOps React 部署: Unable to run the script on Kudu Service.错误:错误:由于超时而无法获取脚本状态

转载 作者:行者123 更新时间:2023-12-03 03:41:08 28 4
gpt4 key购买 nike

我正在尝试通过 Azure Devops 部署 CRA + Craco React 应用程序。这是我的 YML 文件:

# Node.js React Web App to Linux on Azure
# Build a Node.js React app and deploy it to Azure as a Linux web app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

variables:

# Azure Resource Manager connection created during pipeline creation
azureSubscription: '{REDACTED FOR SO}'

# Web app name
webAppName: 'frontend'

# Environment name
environmentName: 'public'

# Agent VM image name
vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)

steps:
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true

- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop

- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: $(environmentName)
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureRmWebAppDeployment@4
displayName: 'Azure App Service Deploy: '
inputs:
ConnectionType: 'AzureRM'
azureSubscription: 'My Subscription'
appType: 'webAppLinux'
WebAppName: 'frontend'
packageForLinux: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
RuntimeStack: 'NODE|10.10'
StartupCommand: 'npm run start'
ScriptType: 'Inline Script'
InlineScript: |
npm install
npm run build --if-present

构建任务成功。但是,运行大约 20 分钟后部署失败,并出现以下错误:

Starting: Azure App Service Deploy: 
==============================================================================
Task : Azure App Service deploy
Description : Deploy to Azure App Service a web, mobile, or API app using Docker, Java, .NET, .NET Core, Node.js, PHP, Python, or Ruby
Version : 4.198.0
Author : Microsoft Corporation
Help : https://aka.ms/azureappservicetroubleshooting
==============================================================================
Got service connection details for Azure App Service:'frontend'
Package deployment using ZIP Deploy initiated.
Deploy logs can be viewed at https://{MYAPPSERVICENAME}.scm.azurewebsites.net/api/deployments/62cf55c3f1434309b71a8334b2696fc9/log
Successfully deployed web package to App Service.
Trying to update App Service Application settings. Data: {"SCM_COMMAND_IDLE_TIMEOUT":"1800"}
App Service Application settings are already present.
Executing given script on Kudu service.
##[error]Error: Unable to run the script on Kudu Service. Error: Error: Unable to fetch script status due to timeout. You can increase the timeout limit by setting 'appservicedeploy.retrytimeout' variable to number of minutes required.
Successfully updated deployment History at https://{MYAPPSERVICENAME}.scm.azurewebsites.net/api/deployments/3641645137779498
App Service Application URL: http://{MYAPPSERVICENAME}.azurewebsites.net
Finishing: Azure App Service Deploy:

最佳答案

此 YML 解决了我的问题,并将 Azure 应用服务节点版本升级到 14.*

我所做的是,我已将 npm install npm run build 移至构建阶段,并将其从部署内联脚本阶段删除。

因此,包在部署之前就已准备就绪,成功解压后,它将使用 pm2serve/home/site/wwwroot/build --no-daemon --spa 作为其运行来启动应用程序在 Linux 应用服务中。 (如果您的构建目录位于 wwwroot 内,则它可以工作),如果不是,请相应地更新路径

  # Node.js React Web App to Linux on Azure
# Build a Node.js React app and deploy it to Azure as a Linux web app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- develop

variables:

# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'YOUR-SUBSCRIPTION'

# Web app name
webAppName: 'AZURE_APP_NAME'

# Environment name
environmentName: 'APP_ENV_NAME'

# Agent VM image name
vmImageName: 'ubuntu-latest'

stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)

steps:
- task: NodeTool@0
inputs:
versionSpec: '14.x'
displayName: 'Install Node.js'

- script: |
npm install
displayName: 'npm install'

- script: |
npm run build
displayName: 'npm build'

- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true

- upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop

- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: $(environmentName)
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureRmWebAppDeployment@4
displayName: 'Azure App Service Deploy: poultry-web-test'
inputs:
azureSubscription: $(azureSubscription)
appType: webAppLinux
WebAppName: $(webAppName)
packageForLinux: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
RuntimeStack: 'NODE|14-lts'
StartupCommand: 'pm2 serve /home/site/wwwroot/build --no-daemon --spa'

关于reactjs - Azure DevOps React 部署: Unable to run the script on Kudu Service.错误:错误:由于超时而无法获取脚本状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71167327/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com