Goal is simple
Deploy wordpress site.
If merge is to “dev” branch… then deploy to namespace in k8 of “dev” and use values_dev.yaml file to deploy wordpress.
variables:
KUBECONFIG: "./files/k3s_kubeconfig.yml"
APP_NAME: wordpress
VALUES: "" # needs placeholder
NAMESPACE: "" # needs placeholder
default:
tags:
- k3s # tag for onsite runner
stages:
- build
# - test
# - deploy
################# BUILD STAGE #################
build-stage:
stage: build
image: alpine/helm:3.2.1
script:
- echo ${APP_NAME}
- echo ${VALUES}
- echo ${NAMESPACE}
- helm repo add bitnami https://charts.bitnami.com/bitnami
- helm upgrade --install ${APP_NAME} bitnami/wordpress --version 19.0.6 --values=./${APP_NAME}/${VALUES} --create-namespace --namespace ${NAMESPACE}
build-stage-dev:
extends: build-stage
rules:
- if: $CI_COMMIT_BRANCH == 'dev'
when: always
variables:
VALUES: "./${APP_NAME}/values_dev.yaml"
NAMESPACE: "net-dev"
# EXTRA_VAR_FILES: " -var-file=./${APP_NAME}/blah.yaml"
build-stage-prod:
extends: build-stage
rules:
- if: $CI_COMMIT_BRANCH == 'main'
when: always
variables:
VALUES: "./${APP_NAME}/values_prod.yaml"
NAMESPACE: "net-prod"
# EXTRA_VAR_FILES: " -var-file=./${APP_NAME}/blah.yaml"
I swear I had it working… it just. worked I even show in history of k8 cluster namepaces. did dev branch… did manual merge to main … two websites… it was beautiful. A few weeks came back to tear down and run again… . now it won’t take any variables from “extends” stanza and use them in “script”
I get error where it does provide variable for upper level variable but ignores those down in extends… which then breaks the whole evaluation logic / purpose to set variables based on pipeline deploy.
Created fresh repository.
Checking out 34d65058 as detached HEAD (ref is dev)...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:03
$ echo ${APP_NAME}
wordpress
$ echo ${VALUES}
$ echo ${NAMESPACE}
$ helm repo add bitnami https://charts.bitnami.com/bitnami
"bitnami" has been added to your repositories
$ helm upgrade --install ${APP_NAME} bitnami/wordpress --version 19.0.6 --values=./${APP_NAME}/${VALUES} --create-namespace --namespace ${NAMESPACE}
Error: flag needs an argument: --namespace
Cleaning up project directory and file based variables
00:00
ERROR: Job failed: command terminated with exit code 1
I read through:
CI/CD YAML syntax reference | GitLab
and saw note " * Doesn’t merge the values of the keys. " but this is not very clear… and… I swear I had this working
Tried to backtrace to code that did work but… too many changes / beers ago.