Skip to content

New predefined variables for job start time and pipeline created time

Release notes

Previously when you wanted to reference the date and time when a job started or a pipeline was created, you would need a script to retrieve these timestamps. Now they are readily available as predefined variables CI_JOB_STARTED_AT and CI_PIPELINE_CREATED_AT, provided in ISO 8601 format and UTC time zone.

Thanks to @Winkies for this contribution!

https://docs.gitlab.com/ee/ci/variables/predefined_variables.html#predefined-variables-reference

Problem to solve

We need a reliable UTC and ISO-8601 compliant date/timestamp indicating the start of a CI job.

Further details

Hopefully there are other use-cases. What prompted me to go looking and, ultimately, to propose this feature was trying to apply standard Docker image labels, specifically: org.opencontainers.image.created ("date and time on which the image was built").

For the time being, I'm making a date call in my before_script:

before_script:
    - export CI_JOB_TIMESTAMP=$(date --utc --iso-8601=seconds)

But, wait, these exact parameters for date are valid on my machine, but not on the gitlab.com shared runners! I had to use a different form.

before_script:
    - export CI_JOB_TIMESTAMP=$(date --utc -Iseconds)

OK, now, what happens when I also have Windows runners? Gah! That's why a nice timestamp from the runner would be lovely 😄

Proposal

Add CI_JOB_STARTED_AT and CI_PIPELINE_CREATED_AT as predefined variables.

What does success look like, and how can we measure that?

A new "predefined" environment variable. My suggestions are...

  • CI_JOB_TIMESTAMP
  • or CI_JOB_STARTED

Links / references

Edited by Thao Yeager