fistameeny
fistameeny

Reputation: 1131

Gitlab CI - build image and pass to next stages?

I'm trying to setup a pipeline using Gitlab CI and PHP/Symfony project. My .gitlab-ci.yml file should contain 3 stages:

I have it working as it should at the moment, but only by running the build steps alongside each test - this means I'm repeating the same build steps twice and it's taking longer than it should.

I know that GitLab allows you to build a Docker image and store it in the project, but for the time being, is there a mechanism to build the Docker image, store it (as an artifact?), and then pass it onto the test stages so they don't need to repeat the build?

Upvotes: 7

Views: 6943

Answers (1)

Stefan van Gastel
Stefan van Gastel

Reputation: 4478

Although using the registry to store the image is indeed the recommended way there is an answer to your question:

In the build stage save the image as a file:

docker save -o myimage.tar myimage:build123

Define myimage.tar as an artifact, use depends_on in the follow-up stage jobs and load the image there:

docker load -i myimage.tar

Upvotes: 7

Related Questions