KUBECONFIG expands to file contents in variable block
Summary
Assigning a variable a value of $KUBECONFIG
in a variable block sets the variable to the contents of the kube config file instead of the path.
Possibly related to #1809 (closed).
Steps to reproduce
- Integrate a project with a k8s cluster, so
KUBECONFIG
is exported in CI jobs. - Run the job definition below.
.gitlab-ci.yml
stages:
- test
test:
stage: test
image: alpine:3.7
environment:
name: staging
variables:
KUBE_CONFIG_PATH: $KUBECONFIG
script:
- echo $KUBECONFIG
- echo $KUBE_CONFIG_PATH
Actual behavior
KUBECONFIG
is set to the kube config file path, but KUBE_CONFIG_PATH
is set to the kube config file contents.
Expected behavior
KUBECONFIG
and KUBE_CONFIG_PATH
are both set to the kube config file path.
Relevant logs and/or screenshots
job log
Running with gitlab-runner 13.9.0-rc2 (69c049fd)
on docker-auto-scale fa6cab46
feature flags: FF_GITLAB_REGISTRY_HELPER_IMAGE:true
Preparing the "docker+machine" executor 00:10
Using Docker executor with image alpine:3.7 ...
Pulling docker image alpine:3.7 ...
Using docker image sha256:6d1ef012b5674ad8a127ecfa9b5e6f5178d171b90ee462846974177fd9bdd39f for alpine:3.7 with digest alpine@sha256:8421d9a84432575381bfabd248f1eb56f3aa21d9d7cd2511583c68c9b7511d10 ...
Preparing environment 00:01
Running on runner-fa6cab46-project-24630127-concurrent-0 via runner-fa6cab46-srm-1614205747-f448df90...
Getting source from Git repository 00:02
$ eval "$CI_PRE_CLONE_SCRIPT"
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/pncc/ci/test/.git/
Created fresh repository.
Checking out aa4cd78b as main...
Skipping Git submodules setup
Executing "step_script" stage of the job script 00:00
Using docker image sha256:6d1ef012b5674ad8a127ecfa9b5e6f5178d171b90ee462846974177fd9bdd39f for alpine:3.7 with digest alpine@sha256:8421d9a84432575381bfabd248f1eb56f3aa21d9d7cd2511583c68c9b7511d10 ...
$ echo $KUBECONFIG
/builds/pncc/ci/test.tmp/KUBECONFIG
$ echo $KUBE_CONFIG_PATH
[REDACTED]
Cleaning up file based variables 00:01
Job succeeded
Environment description
Running on Gitlab.com
Used GitLab Runner version
Running with gitlab-runner 13.9.0-rc2 (69c049fd)
on docker-auto-scale fa6cab46
feature flags: FF_GITLAB_REGISTRY_HELPER_IMAGE:true
Possible fixes
I'm not familiar with the Gitlab codebase, so I'm not sure where a solution might live.
A workaround mentioned in #1809 (closed) is to export KUBE_CONFIG_PATH
in a before_script
block, where the shell will handle the variable expansion as expected:
stages:
- test
test:
stage: test
image: alpine:3.7
environment:
name: staging
before_script:
- export KUBE_CONFIG_PATH=$KUBECONFIG
script:
- echo $KUBECONFIG
- echo $KUBE_CONFIG_PATH