Commit 3ad04339 authored by Hordur Freyr Yngvason's avatar Hordur Freyr Yngvason Committed by James Fargher

Add CI_KUBERNETES_ACTIVE alternative to only:kubernetes:active

This adds a CI variable CI_KUBERNETES_ACTIVE as an alternative to
only:kubernetes:active/except:kubernetes:active for use with the rules
syntax.

This will enable us to move deployment-related Auto DevOps sub-templates
to rules syntax, see
https://gitlab.com/gitlab-org/gitlab/-/issues/213336
parent 5a5cd7e1
......@@ -683,6 +683,8 @@ module Ci
variables.concat(merge_request.predefined_variables)
end
variables.append(key: 'CI_KUBERNETES_ACTIVE', value: 'true') if has_kubernetes_active?
if external_pull_request_event? && external_pull_request
variables.concat(external_pull_request.predefined_variables)
end
......
---
title: Add a CI variable CI_KUBERNETES_ACTIVE as an alternative to only:kubernetes/except:kubernetes
that works with the rules syntax
merge_request: 31146
author:
type: added
......@@ -64,6 +64,7 @@ future GitLab releases.**
| `CI_JOB_TOKEN` | 9.0 | 1.2 | Token used for authenticating with the [GitLab Container Registry](../../user/packages/container_registry/index.md) and downloading [dependent repositories](../../user/project/new_ci_build_permissions_model.md#dependent-repositories) |
| `CI_JOB_JWT` | 12.10 | all | RS256 JSON web token that can be used for authenticating with third party systems that support JWT authentication, for example [HashiCorp's Vault](../examples/authenticating-with-hashicorp-vault). |
| `CI_JOB_URL` | 11.1 | 0.5 | Job details URL |
| `CI_KUBERNETES_ACTIVE` | 13.0 | all | Included with the value `true` only if the pipeline has a Kubernetes cluster available for deployments. Not included if no cluster is availble. Can be used as an alternative to [`only:kubernetes`/`except:kubernetes`](../yaml/README.md#onlykubernetesexceptkubernetes) with [`rules:if`](../yaml/README.md#rulesif) |
| `CI_MERGE_REQUEST_ASSIGNEES` | 11.9 | all | Comma-separated list of username(s) of assignee(s) for the merge request if [the pipelines are for merge requests](../merge_request_pipelines/index.md). Available only if `only: [merge_requests]` or [`rules`](../yaml/README.md#rules) syntax is used and the merge request is created. |
| `CI_MERGE_REQUEST_CHANGED_PAGE_PATHS` | 12.9 | all | Comma-separated list of paths of changed pages in a deployed [Review App](../review_apps/index.md) for a [Merge Request](../merge_request_pipelines/index.md). A [Route Map](../review_apps/index.md#route-maps) must be configured. |
| `CI_MERGE_REQUEST_CHANGED_PAGE_URLS` | 12.9 | all | Comma-separated list of URLs of changed pages in a deployed [Review App](../review_apps/index.md) for a [Merge Request](../merge_request_pipelines/index.md). A [Route Map](../review_apps/index.md#route-maps) must be configured. |
......
......@@ -709,6 +709,28 @@ describe Ci::Pipeline, :mailer do
)
end
end
describe 'variable CI_KUBERNETES_ACTIVE' do
context 'when pipeline.has_kubernetes_active? is true' do
before do
allow(pipeline).to receive(:has_kubernetes_active?).and_return(true)
end
it "is incldued with value 'true'" do
expect(subject.to_hash).to include('CI_KUBERNETES_ACTIVE' => 'true')
end
end
context 'when pipeline.has_kubernetes_active? is false' do
before do
allow(pipeline).to receive(:has_kubernetes_active?).and_return(false)
end
it 'is not included' do
expect(subject.to_hash).not_to have_key('CI_KUBERNETES_ACTIVE')
end
end
end
end
describe '#protected_ref?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment