Interaction between Pipeline and Script

Hello all
I am trying to get any kind of interaction between the pipeline and a script but am unsuccessfull so far.

A simple scenario would be as follows:

  • Pipeline starts
  • Some build is happening and a hash is generated
  • A Docker Registry is checked, if an image with this hash already exists
  • Depending on th this output, a build/push for a Docker is created or not

Now, of course I can just create a single stage that does all that but I think that kind of destroys the purpose of having a “pipeline”. So I would prefer to have multiple stages: Build, Check, Build Image, Push Image.
So, the last two stages would only be called, if the check returns true, otherwise they would be skipped. This all is possible in Jenkins without issues.
Is there any way in GitLab to do something like that? The only way I found to get something working is with using the GitLab API from my script to actually call itself with a different set of parameters.

Thanks for hints.