Group Runners cleanup problem

Hello, I have 2 group runners and one project with .gitlab-ci.yml which includes 3 stages.
I can’t use TAG’s

stages:
** - build**
** - test**
** - cleanup**

My cleanup looks like this:

script:
    - docker rmi -f $IMAGE_NAME

Sometimes stage build is performed on Runner 1 and stage cleanup is performed on Runner 2
The above raises problem as the stage cleanup cannot see images being created on runner 1.

Can I somehow force each stage/job to run on the same runner ?

AFAIK, not directly without using tags.

Your other option might be to refactor your CI config, maybe like this:

stages:
    - build
    - test

.cleanup: &cleanup
    after_script:
        - docker rmi -f $IMAGE_NAME

build:
    <<: *cleanup
    ...

test:
    <<: *cleanup
    ...

The after_script section will run on both passing and failing jobs, BTW.