Permit users to configure pages `expire_in` in gitlab-ci.yml
What does this MR do and why?
This MR adds the expire_in
property to the pages job in .gitlab-ci.yml
to override the instance default for extra deployments.
Screenshots or screen recordings
(No visual changes)
How to set up and validate locally
- Set up your GDK to support Runners and Pages
- Enable the multi version feature flag with
rails c
and thenFeature.enable("pages_multiple_versions_setting")
- Enable the new pages UI feature flag with
rails c
and thenFeature.enable("new_pages_ui")
- Create a Pages project by creating a new project with the "pages/Plain HTML" template.
- Replace the below config in the
.gitlab-ci.yml
:
image: busybox
pages:
stage: deploy
script:
- echo "Pages accessible through ${CI_PAGES_URL}/${PAGES_PREFIX}"
variables:
PAGES_PREFIX: "" # no prefix by default (master)
pages:
path_prefix: "$PAGES_PREFIX"
expire_in: 60 # one minute
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == "master" # ensure to run on master (with default PAGES_PREFIX)
variables:
PAGES_PREFIX: '' # prefix with _stg for the staging branch
- if: $CI_PIPELINE_SOURCE == "merge_request_event" # conditionally change the prefix on Merge Requests
variables:
PAGES_PREFIX: 'mr$CI_MERGE_REQUEST_IID' # prefix with the mr<iid>, like `mr123`
- Ensure the pipeline runs successfully and you have a pages deployment
- Enable multiple deployments for your new project
- Create at least one MR in the project. Ensure each MR's pipeline creates a Pages deployment.
- In the project's sidebar go to Deploy > Pages, view the MR's deployments, click on the chevron and confirm that they now show an expiry date and time that aligns with the
expire_in
property from the.gitlab-ci.yml
- Wait until that expiry date has passed* and confirm that the deployments have been removed (note that they will go first into a "stopped" state before they are permanently removed)
- the cron job only runs at every 10 minute mark, so you may have to wait for the next job run, or update the cron schedule of the
deactivate_expired_deployments_cron_worker
job inconfig/initializers/1_settings.rb
Related to #456478 (closed)
Edited by Janis Altherr