Understanding the build and test stages

I’m a little confused between the build and test stages. For example, I have 2 build stages, one that builds on CentOS, and another that builds on Ubuntu.

Then I want to test the CentOS build on CentOS, and the Ubuntu build on Ubuntu. My first thought was that my test stage could be common, it would start in the directory where the build stage left off. However, the pipeline graph shows I only have one “test” stage, and when it runs, it has a fresh checkout of my project.

I’m not new to GitLab CI, I’ve done many jobs but generally do the build, unit test and some integrations tests all in the “build” stage to the above my issue. My general use case for CI is to build and test across many Linux distributions. I’m just trying to understand the “test” stage to see if it can fall into my use case.


The test stage is a complete different job, you can share artifacts or cache between jobs to get your build project in the test stage. It is just a single job, so you wouldn’t get one for both your builds if you define it only once in the pipeline.
So you’ll need one for both your builds and make sure the build project from the previous stage is shared.
For a shared cache example see https://docs.gitlab.com/ee/ci/examples/artifactory_and_gitlab/index.html and for sharing artifacts there is an example in the answer on https://stackoverflow.com/questions/56721584/gitlab-how-to-use-artifacts-in-subsequent-jobs-after-build