Simple use Extends - Variables for Pipeline

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 :stuck_out_tongue:

Tried to backtrace to code that did work but… too many changes / beers ago.

Ok.

Called a friend… he is peer who is all around a good guy… and in 10 seconds pointed out my issue.

I “cleaned up” my code… which I copied from various places and examples… by removing that annoying and unneeded “.” at the begining :stuck_out_tongue:

Well… That “.” means, dont run this job within the CD process, but parse on and run based on “extras” evaluation, and its variables.

.build-stage:
  stage: build
  image: alpine/helm:3.2.1
  script:
    - echo ${APP_NAME} 
    - echo ${VALUES}
    - echo ${NAMESPACE}
    - apk update
    - apk add curl
    - curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
    - chmod +x ./kubectl ; mv ./kubectl /usr/bin/kubectl
    - pwd
    - kubectl apply -f ./$APP_NAME/wp_storage_claim.yaml
    - kubectl apply -f ./$APP_NAME/wp_cilium_ip.yaml
    - helm repo add bitnami https://charts.bitnami.com/bitnami
    - helm upgrade --install ${APP_NAME} bitnami/wordpress --version 19.0.6 --set "wordpressPassword=${wordpressPassword},global.storageClass=${storageClass},persistence.existingClaim=${existingClaim},mariadb.auth.password=${mariadb_password},mariadb.auth.rootPassword=${mariadb_rootPassword}" --create-namespace --namespace ${NAMESPACE}

build-stage-dev:
    extends: .build-stage
    rules:
    - if: $CI_COMMIT_BRANCH == 'dev'
      when: always
    variables:
      VALUES: "values_dev.yaml"
      NAMESPACE: "net-dev"
      existingClaim: mariadb-pv-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: "values_prod.yaml"
      NAMESPACE: "net-prod"
      existingClaim: mariadb-pv-prod
      # EXTRA_VAR_FILES: " -var-file=./${APP_NAME}/blah.yaml"

thanks