Setup azure-pipelines.yml "Directory '/home/vsts/work/1/a' is empty." with ASP.NET Core
Asked Answered
O

2

6

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://learn.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://learn.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.

Ovalle answered 22/4, 2019 at 15:19 Comment(1)
You are only building the project but you also need to publish it in order for artifacts to appear. Use dotnet publish for that.Lay
T
7

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 task 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.

Totem answered 22/4, 2019 at 15:56 Comment(2)
Point 2. You mean the log?Ovalle
I did. SO requires me to type another sentence before I can say so though.Totem
N
0

Just replace in variables:

**/Dockerfile

…by

$(Build.SourcesDirectory)/Dockerfile

That works for me.

Nolly answered 8/7, 2019 at 21:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.