[CI] Provide a way to use an environment without actually deploying to it.
Problem to solve
Provide a way to use an environment without actually deploying to it.
Intended users
Developers
Further details
Lets assume we use the following .gitlab-ci.yml
:
stages:
- preview
- deploy
preview:dev:
stage: preview
image: ${CI_IMAGE_KUBERNETES}
script:
- kubectl diff -f manifests/
environment:
name: dev
deploy:dev:
stage: deploy
image: ${CI_IMAGE_KUBERNETES}
script:
- kubectl apply -f manifests/
environment:
name: dev
when: manual
In this particular case, we are using GitLab Kubernetes integration. Thus, we need to specify environment
section to get proper kubeconfigs for the environment.
What we want to achieve in CI configuration above is to run some checks/previews against an environment and then deploy to that environment in the next stage.
However, when we specify environment
section, GitLab always assumes that we are deploying to the environment. But we actually don't deploy in "preview" job.
Proposal
GitLab should not always assume that we are deploying to the environment just only using the fact we are using it. We should provide a flexible way to mark actions as "deployments" and possibly others (e.g. previews, rollbacks, etc).
One solution could be introducing new option "action" that specifies our intent, e.g.:
preview:dev:
stage: preview
image: ${CI_IMAGE_KUBERNETES}
script:
- kubectl diff -f manifests/
environment:
name: dev
action: preview
Using this method, GitLab marks the job as a "deployment" only when action == deploy
. Of course, we should keep backwards compatibility, so if no action is specified, we assume action = deploy
by default.
Another more simple approach is to introduce deploy
parameter:
preview:dev:
stage: preview
image: ${CI_IMAGE_KUBERNETES}
script:
- kubectl diff -f manifests/
environment:
name: dev
deploy: false
This way we can mark jobs that are using the environment but not actually deploy anything into it. And again, we keep deploy = true
by default to maintain backwards compatibility.