Re-export file variable in .gitlab-ci.yml?

I’m trying to re-export KUBECONFIG as KUBE_CONFIG_PATH. My issue is that adding

variables:
   KUBE_CONFIG_PATH: $KUBECONFIG

to my .gitlab-ci.yml results in KUBE_CONFIG_PATH being set to the contents of the kube config file instead of the path. I’ve double-checked, and KUBECONFIG is the path to the kube config file, not the contents.

What I expected to happen is that KUBE_CONFIG_PATH would be set to the path of the kube config file.

If I create a variable in the GUI I can set it’s type to “file” to save the value to a file and set the variable to the file’s path (GitLab CI/CD variables | GitLab). This seems like what KUBECONFIG is doing behind the scenes. It doesn’t seem like this is possible when defining a variable in .gitlab-ci.yml however.

For context I am using Gitlab.com, I have integrated a k8s cluster with my project, and I’m running Terraform as a deploy job.

A dummy .gitlab-ci.yml script that replicates my issue is:

stages:
   - test

test:
   stage: test
   image: alpine:3.7
   environment:
      name: staging
   variables:
      KUBE_CONFIG_PATH: $KUBECONFIG
   script:
      - echo $KUBECONFIG
      - echo $KUBE_CONFIG_PATH

This script shows that KUBECONFIG is the file path and KUBE_CONFIG_PATH is the file contents.

Hi @DrewGingerich

I think maybe you need this issue to be resolved first:

?

Regards,

Sarah

Hi @snim2,

Thank you for the response! That looks like it could be it, but it doesn’t touch upon my specific case of KUBECONFIG being expanded in the variables block to the file contents instead of path.

I think I’ll open a new issue to highlight this, making sure to reference the issue you showed me.

In any case I did see a solution in that thread, which is to export the variable in a before_script block:

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
1 Like

I’ve opened an issue here.

1 Like