Gitlab-CI: conditional variables?

Viewed 424

In our gitlab-ci file we have some variables like this:

variables:
  ...
  LOCAL_IMAGE_PHP: $CI_REGISTRY_IMAGE/php:$CI_COMMIT_BRANCH
  ...

Which we use as the image file for another stage:

.build-php:
  ...
  image: $LOCAL_IMAGE_PHP
  ...

We then have a docker image with tag master, staging and develop. So the correct image is automatically chosen based on which branch is currently getting build.

However, we also want to use this to build and run automatic tests on our feature branches. However, no php:feature/something images exist.

Is it possible to conditionally assign another variable based on the value of $CI_COMMIT_BRANCH? Something like DOCKER_TAG: $CI_COMMIT_BRANCH if ($CI_COMMIT_BRANCH in ['master', 'staging', 'develop']) else 'develop'. So DOCKER_TAG would fallback to develop if it's an a feature branch.

So in a way it should select the corresponding docker image on the branches master, staging and develop, but fallback to develop on any other branch.

Is something like that possible? Or is there a different way to handle this kind of scenario?

Thanks!

0 Answers
Related