Jenkins pipeline docker is unable to delete msbuild obj binaries on build agent

Hi…

I am trying to build my .net framework 4.7.2 project (a WCF and WPF application) using jenkins pipeline using docker image (mcr.microsoft.com/dotnet/framework/sdk:4.8-20220215-windowsservercore-ltsc2019) on my machine. This is a POC BTW.

The msbuild command is failing with the below error, I have tried to find solutions over the internet but the solutions I found aren’t working for me. :-

"C:\ProgramData\Jenkins\.jenkins\workspace\MyLocalServicePipeline\MyLocalService.sln" (Rebuild target) (1) ->
"C:\ProgramData\Jenkins\.jenkins\workspace\MyLocalServicePipeline\MyWPFApp\MyWPFApp.csproj" (Rebuild target) (8) ->
(CleanupTemporaryTargetAssembly target) -> 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.WinFx.targets(480,10): error MSB3061:
 Unable to delete file "obj\x64\Release\MyWPFApp.exe". 
Access to the path 'C:\ProgramData\Jenkins\.jenkins\workspace\MyLocalServicePipeline\MyWPFApp\obj\x64\Release\MyWPFApp.exe' is denied.
[C:\ProgramData\Jenkins\.jenkins\workspace\MyLocalServicePipeline\MyWPFApp\MyWPFApp.csproj]

    0 Warning(s)
    1 Error(s)

jenkins pipeline code is as below :-

pipeline {
    agent {
	    docker 
		{ 
			image 'mcr.microsoft.com/dotnet/framework/sdk:4.8-20220215-windowsservercore-ltsc2019'
		}
	} 
    stages {
        stage('Checkout') {
            steps {
                git url: 'https://lasnab82@bitbucket.org/lasnab82/mylocalservice.git'
            }
        }
        stage('NugetRestore') {
            steps {
                bat 'nuget restore "%WORKSPACE%\\MyLocalService.sln"'
            }
        }  
        stage('Build') {
            steps {
				bat '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe" "%WORKSPACE%\\MyLocalService.sln" /t:"Clean" /p:Configuration=Release /p:Platform="x64"'
				bat '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\MSBuild\\Current\\Bin\\MSBuild.exe" "%WORKSPACE%\\MyLocalService.sln" /t:"Rebuild" /p:Configuration=Release /p:Platform="x64"'
            }
        }
    }
}

Logically, I think whats going wrong here is that the jenkins docker container agent may not have delete access to delete files which are actually checked out on my machine in jenkins workspace but I dont know how to resolve this access issue on my setup of jenkins.

Appreciate your help.

Thanks!

It looks like your issue was solved on an other forum:

What was the solution? Because I can’t see any answer.

Not sure what you mean. My issue hasn’t been resolved yet. I have posted the issue yesterday and haven’t got any response except yours. Please let me know if you have any idea.

I mean that the topic name contains “[Solved]”

I have never built Windows Docker images using Jenkins and I don’t see the step which tries to delete.
The error message doesn’t look like it is running inside the container, but when you don’t have access to a file or folder which you created, that could mean that you created with an other user. Maybe created in a container with a Administrator user and saved to a mounted folder and when Jenkins tries to clean your workspace with a non-administrator user, it doesn’t have right to do that.

The error message is part of the msbuild which is running inside a container spun by the jenkins pipeline, msbuild is trying to delete some of the temporary binaries in the final phase of the build.

Yes, the folder where the source resides i.e. the workspace by jenkins is mounted on the container. How can I provide it such privilige that it is able to delete files from the mounted folder ?

P.S - When I am trying to build the same standalone on my PC it runs fine i.e. without docker agent and using my PC as build agent.