I am trying to run my Automation "Specflow+ Runner" C# Test Cases using docker. I have a master.yml file which uses the Shared Agent and it builds docker image using Dockerfile.
master.yml
jobs:
- job: run_docker_build
displayName: Run UI Build
steps:
#------------------------------------------
# Build Docker
#------------------------------------------
- task: Docker@2
displayName: DockerBuild
env:
COMPOSE_DOCKER_CLI_BUILD: 1
DOCKER_BUILDKIT: 1
inputs:
containerRegistry: "XXX"
repository: run-automation-ui
command: build
Dockerfile: '**/Dockerfile'
tags: |
latest
$(Build.BuildId)
#------------------------------------------
# Copy the Results from Build Image
#------------------------------------------
- pwsh: |
$id=docker images --filter "label=Test=True" -q | Select-Object -First 1
docker create --name testcontainer $id
docker cp testcontainer:/src/AutomationTests/TestResults ./TestResults
docker cp testcontainer:/src/AutomationTests/TestResults/Screenshots ./Screenshots
docker rm testcontainer
displayName: 'Copy Test Results'
condition: always()
#------------------------------------------
# Publishing Test Results
#------------------------------------------
- task: PublishTestResults@2
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '**/*.trx'
searchFolder: '$(System.DefaultWorkingDirectory)/TestResults'
publishRunAttachments: true
displayName: 'Publish Test Results'
condition: always()
Docker File
LABEL Test=True
##Method one (#Even if test fails the build task will finish and in later stage I can copy the Results )
#RUN dotnet test -c Release --no-build --logger "trx;LogFileName=/src/AutomationTests/TestResults/test_results.trx" --filter TestCategory=DockerTest || true
#Method Two (#Even if test fails the build task will finish and in later stage I can copy the Results )
#RUN dotnet test -c Release --no-build --logger "trx;LogFileName=/src/AutomationTests/TestResults/test_results.trx" --filter TestCategory=DockerTest; exit 0
#Method Three (#Even if test fails the build task will finish and in later stage I can copy the Results )
#RUN dotnet test -c Release --no-build --logger "trx;LogFileName=/src/AutomationTests/TestResults/test_results.trx" --filter TestCategory=DockerTest; \
#echo $? > /dotnet.exitcode;
#RUN exit $(cat /dotnet.exitcode)
#Method Four (if test fails means still i need to able to copy the results )
#RUN dotnet test -c Release --no-build --logger "trx;LogFileName=/src/AutomationTests/TestResults/test_results.trx" --filter TestCategory=DockerTest
I am looking how can I copy my results if any Tests failed in Dockerfile means