Gitlab-ci: Use Docker Image built in Stage 1 as base image in Stage 2

we currently have a small problem we don’t know how to get around:

Lets say we’ve got a gitlab-ci.yaml like this (it’s a bit dummycode, but you’ll get the point)

        - $version = $(cat VERSION) # VERSION is a file in the repo, content is semver "1.2.3"
        - docker build -t "image_$version"
        - docker push our.gitlab.registry/image_$version
    image: our.gitlab.registry/image_$version
        - test_some_stuff_inside that container

the VERSION file inside the repo contains a semver version string (1.2.3)
Problem is: How can we dynamically get that version in the Test stage, so basically test with the image we just built.
Workaround up to now was to use the gitlab commit id as a version, which can be accessed globally during pipeline runs, but this is messy…
Also it seems to be impossible to change global vars at runtime (so, change this in build step and use it in the definition of the test stage…)
Furthermore, dind is no option.

any ideas?