read input and run based on if condition in .gitlab-ci.yml

7/21/2021

I am trying to automate the creation and deletion of user accounts on the Kubernetes cluster environment. I plan to use the GitLab CI/CD way to do this using a base docker image and placing the manager account config under ~/.kube/config path in it and use that manager account to create/delete accounts on the Kubernetes environment.

Basically, I have both production and the staging Kubernetes cluster environment. I want to do the same action in both environments, whenever a staff joins or leaves.

In .gitlab-ci.yml, under "before_script:", I want to add one condition like:

if the input value is "stage", I want to execute:

echo -n $KUBECTL_STAGING | base64 -d > ~/.kube/config

if the input value is "prod", I want to execute:

echo -n $KUBECTL_PRODUCTION | base64 -d > ~/.kube/config

How to accept input like this and run based on the if condition in .gitlab-ci.yml ?.

-- vjwilson
docker
gitlab
gitlab-ci
gitlab-ci-runner
kubernetes

0 Answers