Use CI_ENVIRONMENT_NAME in only conditional expression

The following works - i can run a pipeline with TARGETJOB set as job1, and it will only run job1
.base_job:
script: echo $CI_JOB_NAME
only:
variables:
- $TARGETJOB == $CI_JOB_NAME

job1:
extends: .base_job

job2:
extends: .base_job
##############################################
This DOESN’T work
.base_job:
script: echo $CI_ENVIRONMENT_NAME, $CI_JOB_NAME
only:
variables:
- $TARGETENV == $CI_ENVIRONMENT_NAME

job1:
extends: .base_job
environment:
name: foo

job3:
extends: .base_job
environment:
name: bar

i.e if i attempt to run this through the Run Pipeline pipeline button (“web” job) suppling TARGETENV with a value of bar, i get

The form contains the following error:

  • No stages / jobs for this pipeline.

Should this work ? When is the CI_ENVIRONMENT_NAME variable made available ?
I’m currently using [11.10.4-ee]
I’ll try it on 12 shortly

I’m trying to set up a project which will provide a way to run a whole heap of manual scripts. A user should be able to stipulate a specific job, an environment to run all jobs in, or for extra marks an environment prefix that matches multiple environments (these environment). It’s for manually, but repeatedly, running scripts, without necessarily having changed them - so it’s definitely not gitops - but still i’d like to see if i can make it work. By leveraging CI_ENVIRONMENT_NAME in the base job i can cut down on the details i need to supply in every job.

Help appreciated !