Can't set "never" as an environment auto_stop_in value
Summary
The documentation for the CI environment "auto-stop" feature indicates that "auto_stop_in
uses the same format of artifacts:expire_in
docs".
However "never" is not a valid option, despite being clearly listed as valid in the artifacts:expire_in
documentation.
This means that the "obvious" way to create persistent environments - setting auto_stop_in
to "never" - doesn't work.
(I understand that you're supposed to use protected environments for production environments, but that's less discoverable if you're looking at environments from the CI YAML reference.)
Documentation links:
- CI YAML reference for
environment:auto_stop_in
: https://docs.gitlab.com/ee/ci/yaml/#environmentauto_stop_in - Environment reference for the "auto-stop" feature: https://docs.gitlab.com/ee/ci/environments/index.html#environments-auto-stop
- CI YAML reference for
artifacts:expire_in
: https://docs.gitlab.com/ee/ci/yaml/README.html#artifactsexpire_in - Protected environments: https://docs.gitlab.com/ee/ci/environments/protected_environments.html
Steps to reproduce
Example .gitlab-ci.yml
file:
deploy_persistent:
script:
- echo "deploy the thing"
environment:
name: persistent-environment
auto_stop_in: never
- Define a pipeline job with an environment that should be persistent
- Set
environment:auto_stop_in
to "never" - Lint the CI script
Example Project
I have not created an example project as the issue can be reproduced with the CI Linter in any project.
What is the current bug behavior?
The current behaviour is that the linting fails with the error:
jobs:deploy_persistent:environment auto stop in should be a duration
What is the expected correct behavior?
According to the documentation, "never" should be a valid duration and therefore the linting should succeed.
I'd expect that an environment created by a job with auto_stop_in
set to "never" would have no "auto stop in" time set, identically to what would happen if the "pin" button had been pressed.
Relevant logs and/or screenshots
gitlab-ci-environment-auto_stop_in-never-bug
Output of checks
This bug happens on GitLab.com.
Possible fixes
When the "environment:auto_stop_in" key was added it was set to be a "duration" type value: !19931 (diffs) (Current code: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/config/entry/environment.rb#L52) However the "artifacts:expire_in" key uses it's own custom parser: https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/config/entry/artifacts.rb#L45
I suspect that the correct fix here is for the environment:auto_stop_in
key to use the same parser and logic as the artifacts:expire_in
key.
However it's also possible that this particular feature - creating environments without an expiry time - is unwanted and the protected environment feature should be used instead, in which case the correct solution here is to update the documentation to make it explicit that environment:auto_stop_in
must be a duration and "never" isn't allowed.
Proposal
Allow a user to define when: never
as part of auto-stop
in