Saad Awan
Saad Awan

Reputation: 666

.NetCore CI pipeline error on docker tasks

I am creating a CI pipeline in Azure for a .NetCore 3.1 application and adding Docker "buildandpush" tasks. i have 2 cases, if i run only .Netcore tasks (restore, build, test, publish) my build success With out any error, if i disable above .NetCore tasks and run only docker(buildAndpublish) Tasks my build success and image pushed into my ACR, but if I enable above .NetCore tasks along with Docker tasks throw an error here.
Can any one tell me the Build definition of .netCore tasks, is i am doing the right things.

ERROR

C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error : Access to the path 'C:\src\RINWeb\obj\RINMVC.csproj.nuget.dgspec.json' is denied. [C:\src\RINWeb\RINMVC.csproj]

Build FAILED.

C:\Program Files\dotnet\sdk\3.1.100\NuGet.targets(123,5): error : Access to the path 'C:\src\RINWeb\obj\RINMVC.csproj.nuget.dgspec.json' is denied. [C:\src\RINWeb\RINMVC.csproj]

0 Warning(s)
1 Error(s)

Time Elapsed 00:00:01.34 The command 'cmd /S /C dotnet build "RINMVC.csproj" -c Release -o /app/build' returned a non-zero code: 1

[error]The process 'C:\Program Files\Docker\docker.exe' failed with exit code 1

My docker file is:

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-nanoserver-1809 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1809 AS build

WORKDIR /src
#####COPY ["RINWeb/RINMVC.csproj", "RINWeb/"]
COPY ["RINMVC.csproj", "RINWeb/"]

RUN dotnet restore "RINWeb/RINMVC.csproj"
#####COPY . .
COPY . RINWeb/
WORKDIR "/src/RINWeb"
RUN dotnet build "RINMVC.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "RINMVC.csproj" -c Release -o /app/publish

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

Upvotes: 0

Views: 456

Answers (1)

Levi Lu-MSFT
Levi Lu-MSFT

Reputation: 30313

You can use two agent jobs to run your pipeline. On agent job to run the dotnet tasks and the second to run the docker task.

If you are using classic view build pipeline. You can click on the (...) on the Pipeline to add an agent job. Please check below screenshot.

enter image description here

Then run docker tasks in agent job2 and configure agent job2 to depend the successful run of agent job1. Please check below screenshot.

enter image description here

If you are using yaml pipeline. You can define multiple jobs. You can check here for more information.

Update:

Here is an example to build and push to ACR in Microsoft. You donot need to use dotnet tasks to build and publish your project only to check if the build is successful or not, since your dockfile is just repeating the the same dotnet commands. You can only use a docker task to build the dockfile.

Or you can modify your dockerfile to only have the last copy step to copy the published files from output folder of the dotnet publish task(remove the dotnet restore, build, publish steps from dockerfile), for your dotnet tasks already did the retore build and publish tasks.

Upvotes: 1

Related Questions