0
votes

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"]
1
Hi. Please refrain from adding images for command output. It makes your post less readable and informative. Moreover, no one can copy/paste the text from the error (if search is needed for example) and it cannot be indexed by internal or external search engines. Please edit your question and paste the relevant docker build stage output in a code block. - Zeitounator
dotnet restore will do changes to your souce folders. You can try moving docker buildAndpublish task to the top of your build pipeline to run it before the dotnet tasks. - Levi Lu-MSFT
@Levi Lu-MSFT yes you rite when I run build without docker tasks , my build got success ed but along with Docker its threw an error and same if I disabled all the .net tasks and run docker tasks its success. But I want to run both tasks .Netcore tasks and docker task so that all the .Netcore build succeeded than I want to move and push my app image into the Azure Container Registry(ACR) - Saad Awan
I think you can separate the docker task in another agent job. So that the docker and dotnet tasks will not affect each other. - Levi Lu-MSFT

1 Answers

1
votes

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.