2
votes

I have a VS 2019 solution containing three .Net Core 3.x Web Api projects that is checked into a Git repo.

I created a build pipeline In Azure DevOps via the wizard targeting my Azure AKS cluster.

The following pipeline YAML file was created..

enter image description here

While running this pipeline, I receive the following exception when it attempts to copy the Web API project files as noted in log below.

Step 6/38 : COPY ["BoundedContexts/BC1/API/NextWare.AppBuilder.BC1.API.csproj", "BoundedContexts/BC1/API/"]

COPY failed: stat /var/lib/docker/tmp/docker-builder568816228/BoundedContexts/BC1/API/NextWare.AppBuilder.BC1.API.csproj: no such file or directory

The file is is in the repository as viewed via Repository Viewer in Azure DevOps

enter image description here

This is the docker file that is failing in Azure DevOps pipeline...

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["BoundedContexts/BC1/API/NextWare.AppBuilder.BC1.API.csproj", "BoundedContexts/BC1/API/"]
COPY ["Infrastructure/NextWare.Infrastructure.EventStore/NextWare.Infrastructure.EventStore.csproj", "Infrastructure/NextWare.Infrastructure.EventStore/"]
COPY ["Infrastructure/NextWare.Infrastructure/NextWare.Infrastructure.csproj", "Infrastructure/NextWare.Infrastructure/"]
COPY ["Infrastructure/NextWare.Infrastructure.EventBus/NextWare.Infrastructure.EventBus.csproj", "Infrastructure/NextWare.Infrastructure.EventBus/"]
COPY ["Infrastructure/NextWare.Infrastructure.EventBus.RabbitMQ/NextWare.Infrastructure.EventBus.RabbitMQ.csproj", "Infrastructure/NextWare.Infrastructure.EventBus.RabbitMQ/"]
COPY ["Infrastructure/NextWare.Infrastructure.Resilience/NextWare.Infrastructure.Resilience.csproj", "Infrastructure/NextWare.Infrastructure.Resilience/"]
COPY ["BoundedContexts/BC1/DomainExceptions/NextWare.AppBuilder.BC1.Domain.Exceptions.csproj", "BoundedContexts/BC1/DomainExceptions/"]
COPY ["BoundedContexts/SharedKernel/NextWare.AppBuilder.SharedKernel.Domain.csproj", "BoundedContexts/SharedKernel/"]
COPY ["Infrastructure/NextWare.Infrastructure.EventBus.ServiceBus/NextWare.Infrastructure.EventBus.ServiceBus.csproj", "Infrastructure/NextWare.Infrastructure.EventBus.ServiceBus/"]
COPY ["BoundedContexts/BC1/Application/NextWare.AppBuilder.BC1.Application.csproj", "BoundedContexts/BC1/Application/"]
COPY ["BoundedContexts/BC1/Infrastructure/NextWare.AppBuilder.BC1.Domain.Infrastructure.csproj", "BoundedContexts/BC1/Infrastructure/"]
COPY ["BoundedContexts/BC1/Domain/NextWare.AppBuilder.BC1.Domain.csproj", "BoundedContexts/BC1/Domain/"]
COPY ["BoundedContexts/SharedServices/Domain/NextWare.AppBuilder.SharedServices.Domain.csproj", "BoundedContexts/SharedServices/Domain/"]
COPY ["BoundedContexts/SharedServices/DomainExceptions/NextWare.AppBuilder.SharedServices.Domain.Exceptions.csproj", "BoundedContexts/SharedServices/DomainExceptions/"]
COPY ["Infrastructure/NextWare.Infrastructure.WebHost/NextWare.Infrastructure.WebHost.csproj", "Infrastructure/NextWare.Infrastructure.WebHost/"]
COPY ["Infrastructure/NextWare.Infrastructure.EventBus.Kafka/NextWare.Infrastructure.EventBus.Kafka.csproj", "Infrastructure/NextWare.Infrastructure.EventBus.Kafka/"]
RUN dotnet restore "BoundedContexts/BC1/API/NextWare.AppBuilder.BC1.API.csproj"
COPY . .
WORKDIR "/src/BoundedContexts/BC1/API"
RUN dotnet build "NextWare.AppBuilder.BC1.API.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "NextWare.AppBuilder.BC1.API.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "NextWare.AppBuilder.BC1.API.dll"]

I am able to build and run this solution within Docker for Windows on my local dev env.

Why am I getting this error?

1
WORKDIR refers to the active directory inside the container. All COPY and ADD commands will target this folder. There is no effect on the host filesystem.bpdohall

1 Answers

3
votes

Try setting the buildContext input of the Docker task at line 34 to $(Build.Repository.LocalPath). If you have multiple repos, try $(Pipeline.Workspace) (ref: Azure Pipelines Predefined Variables)

When I'm having trouble with build context folder structure, sometimes I just throw a little shell script at the beginning to ls some folders or run tree so I can see the structure.