CI_JOB_STARTED_AT and CI_PIPELINE_CREATED_AT contain time in local timezone even though UTC is documented
Summary
The timestamps CI_JOB_STARTED_AT
and CI_PIPELINE_CREATED_AT
are in local time zone, even though the documentation for CI_JOB_STARTED_AT
and CI_PIPELINE_CREATED_AT
states:
UTC datetime when a job started / the pipeline was created, in ISO 8601 format.
According to my understanding, this means that the timestamp should look something like 2021-07-30T12:00:00+00:00
, but in actuality I get 2021-07-30T15:00:00+03:00
when the server's local time is in UTC+3.
Steps to reproduce
- Install GitLab on a server whose local time isn't UTC.
- Add a runner for the server.
- Create a repository with CI script with command
echo $CI_JOB_STARTED_AT
.
Example Project
Example project available at https://version.aalto.fi/gitlab/lievonh1/ci_job_started_at-bug
The CI output available at https://version.aalto.fi/gitlab/lievonh1/ci_job_started_at-bug/-/jobs/22343
What is the current bug behavior?
The timestamps CI_JOB_STARTED_AT
and CI_PIPELINE_CREATED_AT
are in local time zone. For example the example project's CI output contains
$ echo $CI_JOB_STARTED_AT
2021-07-30T12:45:04+03:00
$ echo $CI_PIPELINE_CREATED_AT
2021-07-30T12:45:03+03:00
What is the expected correct behavior?
The timestamps should be in UTC time. For example in the example project I would expect to get
$ echo $CI_JOB_STARTED_AT
2021-07-30T09:45:04+00:00
$ echo $CI_PIPELINE_CREATED_AT
2021-07-30T09:45:03+00:00
Relevant logs and/or screenshots
Pasted above.
Output of checks
Results of GitLab environment info
I don't have access to the server.
Possible fixes
The bug was probably introduced by !54989 (merged) introducing these variables. Based on that MR, the relevant files should be
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/ci/build.rb#L572
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/ci/pipeline.rb#L792
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/models/ci/build_spec.rb#L2590
- https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/models/ci/build_spec.rb#L2639
I'm not familiar with Ruby, but a quick search online suggests that something like the following might work:
- .append(key: 'CI_JOB_STARTED_AT', value: started_at&.iso8601)
+ append(key: 'CI_JOB_STARTED_AT', value: started_at&.utc.iso8601)