【问题标题】:Setup azure-pipelines.yml "Directory '/home/vsts/work/1/a' is empty." with ASP.NET Core设置 azure-pipelines.yml “目录 '/home/vsts/work/1/a' 为空。”使用 ASP.NET 核心
【发布时间】:2019-09-11 18:47:14
【问题描述】:

我非常需要帮助来创建我的 yml 构建文件,因为我在任何地方都找不到任何好的教程、示例或其他帮助之王。我总是收到类似的错误:看到警告,看来我的构建工件总是空的。所有步骤都成功,但我无法部署,因为找不到我的文件。笨蛋。

##[section]Starting: PublishBuildArtifacts
==============================================================================
Task         : Publish Build Artifacts
Description  : Publish build artifacts to Azure Pipelines/TFS or a file share
Version      : 1.142.2
Author       : Microsoft Corporation
Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=708390)
==============================================================================
##[warning]Directory '/home/vsts/work/1/a' is empty. Nothing will be added to build artifact 'drop'.
##[section]Finishing: PublishBuildArtifacts

这是我的管道定义

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'Ubuntu-16.04'

variables:
  buildConfiguration: 'Release'

steps:
# - script: dotnet build --configuration $(buildConfiguration)
#   displayName: 'dotnet build $(buildConfiguration)'

- task: DotNetCoreInstaller@0
  inputs:
    version: '2.2.202' # replace this value with the version that you need for your project

- script: dotnet restore

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    command: build
    projects: '**/*.csproj'
    arguments: '--configuration Release' # Update this to match your need

- task: PublishBuildArtifacts@1
  inputs:
    ArtifactName: 'drop'

注意我评论的 2 行

# - script: dotnet build --configuration $(buildConfiguration)
#   displayName: 'dotnet build $(buildConfiguration)'

实际上是默认脚本的一部分。我没有使用默认脚本。我正在关注教程https://docs.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core?view=azure-devops

还有为什么我不能使用其他项目可用的模板。是因为我使用的是 DevOps 存储库还是因为我的项目有特定的设置?我还有其他项目,我可以使用图形模板和任务管理构建然后部署。容易多了。

【问题讨论】:

  • 您只是在构建项目,但您还需要发布它才能显示工件。为此使用dotnet publish

标签: asp.net-core azure-devops azure-pipelines asp.net-core-2.2


【解决方案1】:

是的,目前对 yaml 管道的帮助似乎有点分散和单薄。

由于您的项目是AspNetCore,我认为您缺少的是dotnet publish 任务,在构建之后和PublishArtifacts 之前:

- task: DotNetCoreCLI@2
  inputs:
    command: publish
    publishWebProjects: True
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: True

但以下是我尝试解决 netcore yaml 管道问题的步骤:

  1. 您已经查看了指南的示例任务和 sn-ps Build, test, and deploy .NET Core apps?

  2. 您注意到您可以单击构建日志来查看管道中每个步骤的详细输出吗?

  3. 您注意到任务DotNetCoreCLI@2 相当于在您自己的桌面上运行dotnet <command>,因此您可以在某种程度上在本地运行/调试这些任务?

  4. 我发现Predefined Variables 提供了一些有用的线索。例如,它告诉我们路径 \agent\_work\1\a 可能是 $(Build.ArtifactStagingDirectory) 变量,所以这有助于我在本地机器上模拟管道。

从逻辑上讲,您的错误消息告诉我们,当管道到达最后一步时,$(Build.ArtifactStagingDirectory) 为空。 dotnetcore 示例页面向我建议 publish 是为 Web 项目填充它的任务。对于其他任何事情,我认为只需 dotnet build 任务就足够了。

【讨论】:

  • 第 2 点。你的意思是日志?
  • 我做到了。 SO 要求我输入另一个句子,然后才能说出来。
【解决方案2】:

只需在变量中替换:

**/Dockerfile

…通过

$(Build.SourcesDirectory)/Dockerfile

这对我有用。

【讨论】:

    猜你喜欢
    • 2020-11-06
    • 1970-01-01
    • 1970-01-01
    • 2022-07-28
    • 1970-01-01
    • 2020-07-28
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多