Same container for building and testing

Hello,

I am working with a .gitlab-ci.yml file in order to build, test and deploy my application each time i merge source files on master branch.

I am working with docker.

Here is one of .gitlab-ci.yml file i am working with:

image: microsoft/dotnet:latest

stages:
  - build
  - test

build:
 stage: build
 script:
   - dotnet restore
   - dotnet build

test:
 stage: test
 script:
   - dotnet test Tests

For each push, i have 2 jobs in 1 pipeline. The 2 jobs are not runned in parallel. Build, then Test.
I have a problem: There are 2 docker containers which are created: One for building and the other for testing.
That mean the build operation is done twice (one for build job, and again for test job).

What should i do in order to work with the same container for all jobs in the same pipeline ?
What i want to do is to keep build result for testing.

Thanks

2 Likes

I am running into the exact same problem.
My current work around is to just put everything in a single job. There must be a better way though. I don’t understand why the default behavior is to make a new container for every single job.