I found a way to create a kind of default variable scenario using rules using different variable names… but I think it would probably work using the same variable name too. This is how I did it:
dotnet_build:
variables:
DEFAULT_IMAGE: mcr.microsoft.com/dotnet/core/sdk:latest
image: $IMAGE_NAME
script:
- dotnet build
rules:
- if: $IMAGE_OVERRIDE != null
variables:
IMAGE_NAME: $IMAGE_OVERRIDE
- when: always
variables:
IMAGE_NAME: $DEFAULT_IMAGE
See discussion on the forum: Override / set default variable value