Is it possible to copy a file from docker container to gitlab repository by gitlab-ci.yml

Viewed 1045

I created a docker image with automated tests that generates a report XML file. After the test run, this file is generated. I want to copy this file to the repository because the pipeline needs this file to show result tests:

tests gitlab

My gitlab script:

    stages:
     - test
    test:
      image: docker:latest
      services:
        - name: docker:dind
          entrypoint: ["env", "-u", "DOCKER_HOST"]
          command: ["dockerd-entrypoint.sh"]
      variables:
        DOCKER_HOST: tcp://docker:2375/
        DOCKER_DRIVER: overlay2
        DOCKER_TLS_CERTDIR: ""
      stage: test
      before_script:
        - docker login -u "xxxx" -p "yyyy" docker.io
      script: 
        - docker run --name authContainer "xxxx/dockerImage:0.0.1"
      after_script:
        - docker cp authContainer:/artifacts/test-result.xml .
      artifacts:
        when: always
        paths:
          - test-result.xml
        reports:
          junit:
             - test-result.xml

Dockerfile:

    FROM mcr.microsoft.com/dotnet/core/sdk:2.1
    
    COPY /publish  /AutomaticTests
    WORKDIR /Spinelle.AutomaticTests
    
    RUN apt-get update -y
    RUN apt install unzip
    
    RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
    RUN dpkg -i google-chrome-stable_current_amd64.deb; apt-get -fy install
    
    RUN curl https://chromedriver.storage.googleapis.com/84.0.4147.30/chromedriver_linux64.zip -o /usr/local/bin/chromedriver
    RUN unzip -o /usr/local/bin/chromedriver -d /Spinelle.AutomaticTests
    RUN chmod 777 /Spinelle.AutomaticTests
     
    CMD dotnet vstest /Parallel AutomaticTests.dll --TestAdapterPath:. --logger:"nunit;LogFilePath=/artifacts/test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose"
1 Answers

You're .gitlab-ci file is looking fine. You can have the XML report as artifact and gitlab will populate the results from that. Below is the script that i've used and could see the results.

  script:
    - pytest -o junit_family=xunit2 --junitxml=report.xml --cov=. --cov-report html
    - coverage report
  coverage: '/^TOTAL.+?(\d+\%)$/'
  artifacts:
    paths:
      - coverage
    reports:
      junit: report.xml
    when: always
Related