I realized that some variables are not the same in the gitlab shared runners and when you use your local configuration.
Simple example of a .gitlab-ci.yml
:
my-test:
image: docker:latest
stage: build
services:
- docker:dind
script:
- env # this is what gives me different results
In order to execute this file I use gitlab-runner exec docker my-test
as explained in https://stackoverflow.com/a/36358790/2237916.
However, the previous code gives me a different result when I push my commits (run in a shared server) and if I run locally. The result is that each one gives me different values on the existent environmental variables. This affects as follows:
- Commands in the script such as
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
are not able to run locally, because none of the 3 variables are set in the local environment. - Kubernetes configuration that is use thanks to variables such as
KUBE_CA_PEM
,KUBECONFIG
KUBE_TOKEN
, and others, are not set.
Thus, I'm unable to replicate experiments locally and remotely (either with a shared runner on my own runner). I'm looking for a straight way to test in local as if I'm really using a shared runner, with all the same environmental variables.
As some complementary information, my current workaround is to use as indicated in a gitlab issue, with the command gitlab-runner exec docker my-test $(printf " --env %s" "${ENVVARS[@]}")
, where ENVVARS
is a bash array. However this is as far as a proper solution as one can be.
Note: I understand that you can set some variables with the options --kubernetes-*
within the command line, this is not desired since you have to set everything every time you run the command. I want to be able to share the same configuration that gitlab
send to the runner.