0
votes

I have self-hosted linux build agent in Azure DevOps. I try to build&push docker task and i have an error like this(locally dotnet build worked):

The specified task executable "node" could not be run. System.ComponentModel.Win32Exception (2): No such file or directory [/src/Cillian.csproj]

My log:

...
Step 11/26 : RUN dotnet build -c Release -o /app
 ---> Running in 9233fd642015
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 1.51 sec for /src/Cillian.csproj.
/root/.nuget/packages/microsoft.typescript.msbuild/3.0.0/tools/Microsoft.TypeScript.targets(293,5): error MSB6003: The specified task executable "node" could not be run. System.ComponentModel.Win32Exception (2): No such file or directory [/src/Cillian.csproj]
...

Pipeline: AzureDevOpsImg

My Dockerfile:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
WORKDIR /src

COPY *.csproj ./
RUN dotnet restore
COPY . .
WORKDIR /src
RUN dotnet build -c Release -o /app

FROM build AS publish

RUN dotnet publish -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Cillian.dll"]
1

1 Answers

0
votes

No such file or directory

Just focus on this error message, dotnet build could not find the csproj file to continue the build. This is the mostly prone error in Azure devops even if it can be built successfully in local.

That is because the docker runs at the Repos/solution level locally(e.g. VS). BUT, for Azure devops CI, it running the docker in the directory where the dockerfile lives, which is at project level.

The nutshell is the relative path which can succeed to used in the local to find csproj, not avilable in the Azure devops at all. Because the working directory has changed.


Please specify $(Build.Repository.LocalPath) to the Docker 2.* argument Build context.

enter image description here

For YAML:

- task: Docker@2
  displayName: build
  inputs: 
    containerRegistry: DockerHub
    repository: xxx/xxx
    Dockerfile: Docker/TestWebApi/Dockerfile
    buildContext: '$(Build.Repository.LocalPath)' # Specify the context
    tags: latest