Middle+
How would you set up dynamic feature-stands in GitLab? The stand is deployed on each push to a branch and removed after merge or after a certain time.
sobes.tech AI
Answer from AI
To set up dynamic feature environments in GitLab, you can use GitLab CI/CD with dynamic environment creation and automatic deletion.
- Configure a job in
.gitlab-ci.ymlthat runs on each push to the desired branch and deploys the environment (for example, in Kubernetes or Docker). - Use the
environmentparameter with a dynamic name, such as based on the branch or commit name. - Set
auto_stop_into automatically delete the environment after a specified time. - Add a job to delete the environment after merge, using rules with
when: manualorwhen: on_successand a merge event check.
Example configuration:
stages:
- deploy
- cleanup
deploy_feature:
stage: deploy
script:
- ./deploy.sh $CI_COMMIT_REF_NAME
environment:
name: feature/$CI_COMMIT_REF_NAME
url: https://$CI_COMMIT_REF_NAME.example.com
auto_stop_in: 1 day
only:
- branches
cleanup_feature:
stage: cleanup
script:
- ./cleanup.sh $CI_COMMIT_REF_NAME
when: manual
environment:
name: feature/$CI_COMMIT_REF_NAME
action: stop
only:
- master
Thus, each push creates a separate environment that will automatically be deleted after a day or manually after merging.