【问题标题】:Azure DevOps ASP.NET Web API Could not download zip YAML issueAzure DevOps ASP.NET Web API 无法下载 zip YAML 问题
【发布时间】:2021-01-07 08:28:19
【问题描述】:

我正在尝试使用 Azure DevOps 将 .NET(不是 .NET Core)Web api 部署到 Azure Web 应用程序。它是一个标准问题 Web api,我在本地运行或通过 Visual Studio Code Azure Deploy 扩展部署都没有问题。

我有以下 YAML 文件。整个管道运行良好,没有任何错误。 YAML 文件本身没有错误。

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop    


- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
    includeRootFolder: false    

- task: AzureWebApp@1
  inputs:
    azureSubscription: 'BariBasicConnection'
    appName: 'baribasicsapiserverjune21st2020b'
    package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'      

网络应用程序本身,当我尝试加载时,它会给出以下错误。

服务不可用。

而且,当我通过 Kudu 检查应用程序文件时,我在 wwwroot 文件夹的 webconfig 文件中看到了这个。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name = "Site Unavailable" stopProcessing = "true">
                    <match url = ".*" />
                    <action type = "CustomResponse" statusCode = "503" subStatusCode = "0" statusReason = "Site Unavailable" statusDescription = "Could not download zip" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration> 

在这一点上,我很确定,我没有选择合适的文件夹来部署或其他东西,但 Azure DevOps 主要关注 .NET Core 和 Node,我发现很难找到 .NET 特定的相关解决方案。

【问题讨论】:

  • 尝试运行命令行任务以将所有文件导出到日志以找到正确的路径:cd "$(build.artifactStagingDirectory)" &amp; dir /s /b,这应该可以让您找到您尝试部署的 zip 文件的实际路径。跨度>
  • 实际上,我希望有人可以帮助我在这种情况下使用正确的默认构建文件夹。
  • 实际上没有“默认路径”...因为默认包含项目的名称,并且会受到许多 msbuild 变量和项目配置的影响。你的 YAML 是相当不错的默认值。运行一次dir /s /b 应该会告诉您放入 YAML 的正确路径,然后您可以在该调用中删除它。
  • 我认为我们在这里忽略了重点。我的问题不是构建文件夹的去向。我试图弄清楚,无论它走到哪里,我怎样才能把它捡起来,然后把它放在网络应用程序上。我已经通过 drop 工件看到了部署文件,所以到目前为止一切都很好。
  • AzureWebApp 任务应该会为您解决这个问题...通过将路径传递给部署 zip。

标签: azure azure-devops azure-pipelines


【解决方案1】:

我花了 6 个小时浏览大约 100 个 azure doc 文件,但终于让它工作了。

我发现了一些事情。

  • 主要问题是 AzureWebApp@1。这根本不是 .NET 项目的部署组件。
  • 此外,打包程序已经在生成一个 zip 文件。因此,我的文件中的 zip 和 unzip 组件实际上是不需要的。但我还是把它留在那里,因为它是其他项目所必需的。我花了一段时间才弄明白。

这是完整的 YAML 文件。

# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4

# commit made to the master branch triggers the pipeline run.

trigger:
- master

# agent pool to run
pool:
  vmImage: 'windows-latest'

# standard variables for a asp.net project deployment

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

# .net needs all those nuget packages installed

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

# this is the building of the project

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

# run the unit tests 

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'


# publish the build artifacts
# this is where you get the deployment settings
# the deployment zip folder that you can later use for other things.
- task: PublishBuildArtifacts@1
  inputs:
    pathToPublish: '$(Build.ArtifactStagingDirectory)'
    artifactName: drop    
    
# archive the build artifact for later processing

- task: ArchiveFiles@2
  inputs:
    rootFolderOrFile: '$(Build.ArtifactStagingDirectory)'
    includeRootFolder: false  

# Extract files
# Extract a variety of archive and compression files such as .7z, .rar, .tar.gz, and .zip
# just extract it as an extra step

- task: ExtractFiles@1
  inputs:
    archiveFilePatterns: '$(Build.ArtifactStagingDirectory)/**/$(Build.BuildId).zip' 
    destinationFolder: '$(Build.ArtifactStagingDirectory)/temp1'
    cleanDestinationFolder: false

# finally deploy it.

- task: AzureRMWebAppDeployment@4
  inputs:
    Package: '$(Build.ArtifactStagingDirectory)/projectname.zip'
    appType: 'webApp'
    ConnectedServiceName: ''
    WebAppName: ''

完整的 repo 也在这里 - https://github.com/Jay-study-nildana/APIServerDotNetWithSimplePasswordToken/blob/master/azure-pipelines.yml

【讨论】:

  • 太棒了!感谢您在此处分享您的解决方案,您可以接受它作为答案,这样它可以帮助遇到相同问题的其他社区成员,我们可以归档这个帖子,谢谢。
  • 我就是这么做的。感谢您关注我不断发布的这些解决方案。我正在为我的项目学习 devops 的东西,并在堆栈上分享现成的解决方案来帮助一般的开发者社区
猜你喜欢
  • 2021-08-09
  • 2021-11-16
  • 2019-05-12
  • 1970-01-01
  • 2020-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多