I use a dockerfile in my project as follows
FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["projectfolder/projectname.csproj", "projectfolder/"]
COPY ["projecttestsfolder/projecttestsname.csproj", "projecttestsfolder/"]
COPY ["solution.sln", "solution.sln"]
RUN dotnet restore "solution.sln"
COPY . .
RUN dotnet build "solution.sln" -c Release --no-restore
FROM build AS test
WORKDIR "/src/projecttestsfolder"
RUN dotnet test "projecttestsname.csproj" -c Release --no-build --logger:trx
RUN cat /src/projecttestsname/TestResults/*.trx
FROM scratch as export-test-results
COPY --from=test /src/projecttestsname/TestResults/*.trx .
FROM build AS publish
WORKDIR "/src/projectfolder"
RUN dotnet publish "projectname.csproj" -c Release --no-build -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "projectname.dll"]
The docker command I use is
docker build --file projectfolder/Dockerfile --target export-test-results --output type=local,dest=out .
When I run this on my local docker desktop I get get a folder created called out and in there I can find my trx file
However ...
When I run the same command via a Jenkins declarative pipeline I don't get ant output in the
pipeline {
agent any
stages {
stage('fetch from git'){
steps {
git credentialsId:'git lab credentials', url: 'gitlab instance url'
}
}
stage('run test') {
steps {
sh 'docker build --no-cache --file foldername/Dockerfile --target export-test-results --output type=local,dest=out .'
sh 'ls'
}
}

I'm expecting an out folder to be shown