Setup azure-pipelines.yml “Directory '/home/vsts/work/1/a' is empty.” with ASP.NET Core

坚强是说给别人听的谎言 提交于 2019-12-11 01:02:36

问题


I seriously need help to create my yml build file because I cannot find any good tutorial, sample or other king of help anywhere. I always get similar error: See the warning, it seems my build artifact is always empty. All step are succes but I cannot deploy because my files are not found. Stupid.

##[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

Here is my pipeline definition

# 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'

Note the 2 line I commented

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

are in fact part of the default script. I'm not using the default script. I'm following the tutorial https://docs.microsoft.com/en-us/azure/devops/pipelines/languages/dotnet-core?view=azure-devops

Also why I cannot use the templates available for my other projects. Is it because I'm using DevOps repository or because my project has specific settings? I have other project I can manage the build then deployment with graphical template and task. A lot more easier.


回答1:


Yes, help on yaml pipelines seem a bit scattered and thin on the ground at the moment.

Since your project is AspNetCore, I think what you're missing is the dotnet publish task, after the build and before the PublishArtifacts:

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

But here are steps I have been through trying to resolve frustration with netcore yaml pipelines:

  1. You have already looked through the guide's example tasks & snippets at Build, test, and deploy .NET Core apps ?

  2. You have noticed that you can click on the build log to see the detailed output of each step in your pipeline?

  3. You have noted that the task DotNetCoreCLI@2 is equivalent to running dotnet <command> on your own desktop so you can to some extent run/debug these tasks locally?

  4. I found Predefined Variables gave some helpful clues. For instance it tells us that the path \agent\_work\1\a is probably the $(Build.ArtifactStagingDirectory) variable, so that helped me in mimicking the pipeline on my local machine.

Logically, your error message tells us that $(Build.ArtifactStagingDirectory) is empty when the pipeline reaches the last step. The dotnetcore example page suggests to me that publish is the task that populates it for a web project. For anything else, I think just the dotnet build task is enough.




回答2:


Just replace in variables:

**/Dockerfile

…by

$(Build.SourcesDirectory)/Dockerfile

That works for me.



来源:https://stackoverflow.com/questions/55796711/setup-azure-pipelines-yml-directory-home-vsts-work-1-a-is-empty-with-asp-n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!