Can variables have non-constant values?

In particular, I want to compute the value as with:

variables:
“D”: $(date --iso-8601)

But I want the date to be computed and locked at the time of assignment rather than expanded and recomputed by each and every shell that references it.

Is there a way to do this within my .gitlab-ci.yml? Or am I just stuck with creating a “helper” stage that writes the value to a file, making that file an artifact, and then reading it in every time I want to reference the value? Seems like a lot of work (and time) for a fairly simple concept.

Hi @agapanthusblue
I don’t think so, because it needs to be compatible with any shell that Runner could use, including Powershell where Bash expansion won’t work.
For your particular use case is a new predefined variable CI_PIPELINE_CREATED_AT - The UTC datetime when the pipeline was created, in ISO 8601 format. available from 13.10

“shell” is a false argument here since jobs are inherently and implicitly OS specific by script anyway. That hasn’t been a significant problem. Shell escapes wouldn’t be any more problematic since it’s essentially the same issue.

Thanks for the pointer to the new variable. I hadn’t seen that one documented yet. It doesn’t solve my problem, (wrong version, wrong format), but it’s interesting to know about.