Environment variable per pipeline fails sometimes

I configured a pipeline with an environment variable per pipeline, but it fails sometimes. It starts like following:

---
kind: pipeline
name: build and publish
type: docker

trigger:
  branch:
    - main
  event:
    - push

clone:
  disable: true

environment:
  INFINISPAN_VERSION: 14.0.6.Final

steps:
  - name: clone
    image: alpine/git
    commands:
      - git clone --tags https://github.com/infinispan/infinispan-quarkus.git .
      - if [ -z "$${INFINISPAN_VERSION}" ]; then echo "cannot find version of infinispan"; return 1; else echo $${INFINISPAN_VERSION}; fi
      - git checkout $${INFINISPAN_VERSION}

Sometimes it works as expected and the version gets printed, else it fails cause environment variable is empty.

I thought to have configured it like documented: Syntax | Drone
The environment variable is reused at subsequent steps, too. Do I need to configure it somehow different, but still define the version only once?