Check if Kubernetes integration is active in 'only' and 'except' conditions
Description
With Auto DevOps (#35712 (closed)) we want to introduce a single .gitlab-ci.yml
that works for all projects. This includes deploy to a Kubernetes cluster, but there are many cases where this is not configured, and so the deploy would fail.
To prevent this, a change in the .gitlab-ci.yml
syntax is needed. It adds capabilities to select if a job should be executed or not if specific environment variables are set, extending only
and except
. This is good since it allows to avoid creating the job if conditions are not met, saving a lot of runner resources.
Old description
production:
stage: production
script:
- some deploy script
environment:
name: production
url: http://$CI_PROJECT_PATH_SLUG.$KUBE_DOMAIN
when: manual
only:
- master
- $KUBECONFIG
But it might be better to add a new keyword like condition
, and allow more complicated logic like condition: $DEPLOY_STRATEGY==prod
. Since this is still fundamentally affecting which jobs get instantiated, this condition should be a sub-keyword of only
. e.g.:
production:
stage: production
script:
- some deploy script
environment:
name: production
url: http://$CI_PROJECT_PATH_SLUG.$KUBE_DOMAIN
when: manual
only:
- master
- condition: $DEPLOY_STRATEGY==prod
I don't really like that it's in the array though, especially because the array otherwise is a logical OR of all it's array entries, but we want this to be a logical AND.
Proposal
Proposal is to implement a new keyword under only
and except
, that specifically checks if Kubernetes is available.
job:
only:
refs:
- master
- tags
kubernetes: active
It checks if a Kubernetes cluster has been configured in as an integration service for the specific project, and if the integration is active.
A more generic solution has been moved to #37397 (closed).
Links / references
- Auto DevOps (#35712 (closed))
- Extend 'only' and 'except' to add environment variables and boolean logic (#37397 (closed))
Feature checklist
Make sure these are completed before closing the issue, with a link to the relevant commit.
-
Feature assurance -
Documentation -
Added to features.yml