Using bash substitution parameter in gitlab-ci.yml


I would like to make some substitution in pre-defined environment variables before running a job (using Bash’s Shell Parameter Expansion feature)


  image: myuser/myimage:${CI_COMMIT_TAG%.*}
   - make

I was not able to make it working and didn’t find anything in docs related to that feature.

If this feature doesn’t exist yet, I will find helpul to have it.

Hello @nqb,

I am not sure if changing the the pre-defined environment is feasible but maybe it’s worth looking to changing it in .pre stage with a bash script/command since all the changes in .pre stage are available to every other pipeline.

I hope that helps.

Hello @rotanak,

I am not sure if changing the the pre-defined environment is feasible

Already tried, it’s not possible and that’s make sense.

My idea is not to modify them, just play with their values to fit my needs:

$ CI_COMMIT_TAG=v0.0.1
$ echo ${CI_COMMIT_TAG%.*}

In fact, I want a feature that let me use modified values of pre-defined environments variables to define jobs parameters without having to “eval” the variables. Because evaluate variables can only occur when job has started (see example in documentation).

That really simplify jobs definition and avoid DRY.

Regarding .pre stage, I don’t think you can evaluate a variable in this stage and export it to other stages.


In that case, would you mind sharing your thought?
what your goal is in term of modifying their values?
It would allow us to have a better overview and provide answer that tailor to your need.