jenkins pipeline docker is unable to delete msbuild obj binaries on build agent
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!