Gitlab AutoDevops environment variable does not apply

4/9/2020

I tried to setup gitlab, kubernetes at AWS EC2 for devops.

Everything is working right. but variables do not applying to Production stage.

Below is my gitlab-ci.yml

image: alpine:latest

variables:
  # KAFKA CONFIG
  KAFKA_HOST: 'KAFKA_HOST'
  KAFKA_PORT: '9092'
  KAFKA_CLIENT_ID: 'k8s_autodevops_client_id'
  KAFKA_CONSUMER_GROUP_ID: 'k8s_autodevops_client_id'

  DOCKER_DRIVER: overlay2

  ROLLOUT_RESOURCE_TYPE: deployment

  DOCKER_TLS_CERTDIR: ""  # https://gitlab.com/gitlab-org/gitlab-runner/issues/4501

  CODE_QUALITY_DISABLED: "true"
  PERFORMANCE_DISABLED: "true"

stages:
  - build
  - test
  - production
  - performance
  - cleanup

production:
  image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image:v0.12.1"
  stage: production
  script:
    - auto-deploy check_kube_domain
    - auto-deploy download_chart
    - auto-deploy ensure_namespace
    - auto-deploy initialize_tiller
    - auto-deploy create_secret
    - auto-deploy deploy
    - auto-deploy delete canary
    - auto-deploy delete rollout
    - auto-deploy persist_environment_url
  environment:
    name: production
    url: http://$CI_PROJECT_PATH_SLUG.$KUBE_INGRESS_BASE_DOMAIN
  artifacts:
    paths: [environment_url.txt]

include:
  - template: Jobs/Build.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Build.gitlab-ci.yml
  - template: Jobs/Test.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Test.gitlab-ci.yml
  - template: Jobs/Code-Quality.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Jobs/Code-Quality.gitlab-ci.yml
  - template: Security/Container-Scanning.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/Container-Scanning.gitlab-ci.yml
  - template: Security/Dependency-Scanning.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/Dependency-Scanning.gitlab-ci.yml
  - template: Security/License-Management.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/License-Management.gitlab-ci.yml
  - template: Security/SAST.gitlab-ci.yml  # https://gitlab.com/gitlab-org/gitlab-foss/blob/master/lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml

That KAFKA prefixed variables are applied to build, test stage.

but not applied only production stage.

I also tried to add variables to Gitlab project Settings -> CI/CD -> variables

and the same result.

Cannot found my custom variables KAFKA_* things.

Any other way to apply variables for production stage??

P.s. gitlab version is 12.9.2-ee and using Gitlab managed GCP Kubernetes Engines

-- Whitehander
devops
gitlab
gitlab-ci-runner
google-kubernetes-engine

1 Answer

4/13/2020

That's my misunderstanding.

Add 'K8S_SECRET_' prefix to variables, they are applied to the Production stage.

Because the Test stage is running on herokuish, but the Production stage is running kubernetes cluster with auto_deploy container.

-- Whitehander
Source: StackOverflow