kims-platform turns a commit into a running CMS: it checks the code, builds the one KIMS v2 image, pushes it to KIMS's registry and deploys it to EKS with Helm. One job per environment folder.
Who does this: whoever has rights to create jobs in KIMS's Jenkins (KIMS's admin, or our engineer if KIMS gives the rights). Our engineer gives the settings and watches the first run.
#Before you start
- The
kims-buildagent is online with every tool (Agent). - The plugins are installed (Plugins).
- The folder
kims-production(orkims-uat) exists withkims-helm-values, andkims-registry/kims-kubeconfigunless the agent has its own access (Credentials). - The code is in KIMS's Git:
mainfor production, anduatfor UAT (Push the code). - The namespace and its four Secrets exist (Secrets). The deploy waits for pods that need them.
- The registry repository exists, for example
kims/kims-v2in ECR (ECR).
#What the job does, stage by stage
| Stage | What runs | Stops when |
|---|---|---|
| Checkout | checkout scm; works out the branch and the environment; sets the build's name to #<n> <environment> <first 12 of the commit SHA> |
REGISTRY is empty, or DEPLOY is ticked on a branch that is neither main nor uat |
| Install | node --version && npm ci |
npm registry not reachable, wrong Node version |
| Verify | npm run verify (type checks, lint, tests, build checks) |
Any check fails |
| Image | If <REGISTRY>/<IMAGE_NAME>:<full commit SHA> already exists, reuses it. Otherwise creates the buildx builder kims-builder (first time only) and runs docker buildx build --platform <PLATFORMS> --file deploy/Dockerfile --push |
Registry login or push fails |
Deploy (only if DEPLOY is ticked) |
Checks the values file's KIMS_ENVIRONMENT against the branch, then helm upgrade --install <HELM_RELEASE> deploy/helm/kims --namespace <namespace> --values <kims-helm-values> --set image.repository=... --set image.tag=<SHA> --wait --timeout 10m, then kubectl rollout status deployment/<HELM_RELEASE>-cms --timeout 5m |
The values file is the other environment's; the migrate hook fails; pods do not become ready in time |
Options set by the Jenkinsfile: one run at a time (disableConcurrentBuilds), a 60 minute timeout, the last 30 builds kept. Nothing else in the job's configuration needs setting for these.
#Create the job
- Open the folder:
<JENKINS_URL>/job/kims-production/(UAT:kims-uat). - New Item.
- Enter an item name:
kims-platform. - Choose Pipeline. OK.
- Description:
KIMS v2: verify, build the image, deploy to EKS (production). - Triggers (named Build Triggers on older versions): see Choose the trigger.
- Scroll to Pipeline. Definition: Pipeline script from SCM.
- SCM: Git.
- Repository URL:
<KIMS_GIT_URL>, the KIMS v2 repository in KIMS's Git. - Credentials: the Git credential (Credentials). The red "Failed to connect to repository" message under the URL must go away once it is chosen.
- Branches to build, Branch Specifier:
*/mainfor production,*/uatfor UAT. - Script Path:
deploy/jenkins/Jenkinsfile.platform. - Lightweight checkout: leave ticked.
- Save.
The job is now at <JENKINS_URL>/job/kims-production/job/kims-platform/.
#Choose the trigger
KIMS decides. The Jenkinsfile sets no trigger itself, so what is set here stays.
| Option | Set in Triggers | Notes |
|---|---|---|
| Webhook from KIMS's Git server | GitHub hook trigger for GITScm polling, or the GitLab / Bitbucket equivalent from their plugin | Fastest. KIMS's Git server must reach Jenkins |
| Polling | Poll SCM, Schedule: H/5 * * * * |
Checks every 5 minutes. Works when Git cannot reach Jenkins |
| By hand only | nothing ticked | Some teams want production deploys started by a person. Then press Build with Parameters after moving main |
Production deploys whatever reaches main. With UAT, main only moves after KIMS accepts a commit on uat (Environments), and production's run reuses UAT's image of that commit.
#The parameters
The pipeline declares them. Jenkins learns them on the job's first run; after that, Build with Parameters shows them. Set REGISTRY at least.
| Parameter | Type | Default | Set to |
|---|---|---|---|
REGISTRY |
String | (empty) | The registry host, for example <ACCOUNT_ID>.dkr.ecr.ap-south-2.amazonaws.com. No https://, no path |
IMAGE_NAME |
String | kims/kims-v2 |
The repository in the registry |
REGISTRY_CREDENTIALS_ID |
String | kims-registry |
Empty for ECR with the credential helper, or any agent already logged in |
PLATFORMS |
String | linux/amd64,linux/arm64 |
Once KIMS's EKS node architecture is known, just that one (for example linux/amd64) to build in about half the time |
KUBECONFIG_CREDENTIALS_ID |
String | kims-kubeconfig |
Empty when the agent has its own cluster access |
HELM_VALUES_CREDENTIALS_ID |
String | kims-helm-values |
Leave it |
HELM_RELEASE |
String | kims |
Leave it. Pod, Deployment and Job names start with it (kims-cms, kims-worker, kims-migrate) |
NAMESPACE |
String | (empty) | Leave empty: production gets kims, UAT gets kims-uat. Set it only if KIMS uses another namespace |
DEPLOY |
Boolean | ticked | Untick to build and push without deploying |
#Make the defaults stick
A value typed into Build with Parameters applies to that run only. To change a default for every run (for example REGISTRY, or empty REGISTRY_CREDENTIALS_ID), the Jenkinsfile's defaults would be used again on the next run, because a Declarative pipeline rewrites its parameter definitions each time it runs. So:
- For a webhook or polling trigger, which passes no values, the Jenkinsfile's defaults are what run. An automatic run fails at Checkout with "Set the REGISTRY parameter" because
REGISTRYhas no default in the code. - The way round, without a code change: run by hand with Build with Parameters, or ask us for a change that reads the registry from the values file. Raise this with KIMS before relying on automatic deploys.
This is a gap in the code as it stands: an automatic (webhook or polling) run of kims-platform has no way to get REGISTRY and stops at Checkout. Until it is changed, start kims-platform with Build with Parameters.
#The branch guard
The Checkout stage takes the environment from the branch it built:
| Branch | Environment | Default namespace |
|---|---|---|
main |
production |
kims |
uat |
uat |
kims-uat |
| anything else | none | none: with DEPLOY ticked the run stops with Branch '<name>' deploys nowhere: production deploys from main, UAT from uat. Untick DEPLOY to only build it. |
Then the Deploy stage reads KIMS_ENVIRONMENT from the folder's kims-helm-values file and stops if it differs:
The Helm values file says KIMS_ENVIRONMENT 'uat', but branch main deploys production. Check the kims-helm-values credential in this folder.This is what stops UAT's database and buckets being deployed into production.
#First run
- Open the job. The first time there is only Build Now (Jenkins does not know the parameters yet).
- Build Now. This run stops at Checkout with
Set the REGISTRY parameter to KIMS's image registry.That is expected: it teaches Jenkins the parameters. - Refresh the page. Build with Parameters is now there.
- Build with Parameters: fill
REGISTRY, emptyREGISTRY_CREDENTIALS_IDand/orKUBECONFIG_CREDENTIALS_IDif the agent has its own access, leave the rest. Build. - Open the run, Console Output (or Pipeline Overview / Stages) and follow it.
The first run takes longest: npm ci with an empty npm cache, the buildx builder being created, and both architectures built from scratch. Later runs reuse the caches.
#What success looks like
- Every stage green.
- The run's name:
#2 production 535cdc7xxxxx(the environment and the first 12 characters of the commit). - The end of the console:
Deployed <REGISTRY>/kims/kims-v2:<full SHA> to production (namespace kims)andFinished: SUCCESS. - In the registry, the tag
<full SHA>with both architectures (or the one inPLATFORMS).
#Check the cluster
From a machine with access to the cluster (kubectl and Helm, EKS):
kubectl -n kims get pods,jobs,cronjobs
helm -n kims history kimskubectl -n kims get pods,jobs,cronjobs
helm -n kims history kimskubectl -n kims get pods,jobs,cronjobs
helm -n kims history kimsYou should see kims-cms-... and kims-worker-... pods Running with READY 1/1, the kims-migrate Job Complete (or already removed by Helm's hook policy), one CronJob per scheduled task, and a Helm revision with STATUS deployed and the chart description Install complete or Upgrade complete.
Then the readiness check:
kubectl -n kims port-forward svc/kims-cms 3000:80 &
sleep 2
curl -s "http://localhost:3000/api/health?check=ready"; echo
kill %1kubectl -n kims port-forward svc/kims-cms 3000:80 &
sleep 2
curl -s "http://localhost:3000/api/health?check=ready"; echo
kill %1$pf = Start-Process kubectl -ArgumentList "-n","kims","port-forward","svc/kims-cms","3000:80" -PassThru -WindowStyle Hidden
Start-Sleep -Seconds 2
curl.exe -s "http://localhost:3000/api/health?check=ready"
Stop-Process -Id $pf.IdYou should see {"status":"ready","database":"ok"}. More checks are on First deploy.
#Run it again later
- New code: happens on its own by the trigger (subject to Make the defaults stick), or Build with Parameters.
- Same commit again (for example after changing
kims-helm-values): Build with Parameters. The image already exists, so the Image stage prints<image> is already in the registry; deploying it as it is.and only the Deploy stage does real work. - Build an image without deploying: untick
DEPLOY.
#Roll back
Two ways, both on Day two:
- Rerun on an earlier commit. In KIMS's Git, the branch must point at that commit (Jenkins builds the branch head). The image for that commit is still in the registry, so it deploys at once.
- Helm rollback from a machine with cluster access, then let the next normal deploy move forward again:
helm -n kims history kims
helm -n kims rollback kims <REVISION>helm -n kims history kims
helm -n kims rollback kims <REVISION>helm -n kims history kims
helm -n kims rollback kims <REVISION>A rollback does not undo database migrations. Migrations are written to be backward compatible, but check with us before rolling back across a release that added migrations.
#If it goes wrong
| Where it stops | What you see | Likely cause | What to do |
|---|---|---|---|
| Checkout | Set the REGISTRY parameter to KIMS's image registry. |
First run, or a triggered run | Expected on the first run. Later: Build with Parameters with REGISTRY |
| Checkout | Branch '<name>' deploys nowhere |
The job's Branch Specifier is not */main or */uat |
Fix the specifier, or untick DEPLOY to only build |
| Checkout | Failed to connect to repository or Authentication failed |
Git credential missing or no network to KIMS's Git | Fix the job's SCM credential; check the agent reaches Git |
| Install | EBADENGINE, npm ERR! network |
Wrong Node, or no npm registry access | Agent |
| Verify | A test or type check fails | A real code problem, or a broken checkout | Read the first error in the log; tell us |
| Image | ERROR: failed to solve ... unauthorized / denied |
No push access | ECR: the agent role's ECR permissions and the credential helper; others: kims-registry |
| Image | permission denied while trying to connect to the Docker daemon socket |
Agent user not in docker group |
Agent |
| Deploy | The Helm values file says KIMS_ENVIRONMENT ... |
The folder holds the other environment's values file | Replace kims-helm-values |
| Deploy | Kubernetes cluster unreachable or Unauthorized |
No kubeconfig, expired credentials, or no EKS access entry for the agent role | Credentials: kims-kubeconfig |
| Deploy | pre-upgrade hooks failed / job failed: BackoffLimitExceeded |
The migrate Job failed (database unreachable, wrong URL) | kubectl -n kims logs job/kims-migrate; the running version stays up |
| Deploy | timed out waiting for the condition |
Pods not ready within 10 minutes | kubectl -n kims describe pod <pod> and its events: image pull, missing Secret, readiness check |
More in Jenkins troubleshooting.
#Sources
kims-v2/deploy/jenkins/Jenkinsfile.platform(main)kims-v2/deploy/jenkins/README.md(main), sections 3 and 5kims-v2/docs/ON-SITE-DEPLOYMENT.md(main), "Production, and UAT if KIMS wants it" and step 4kims-v2/deploy/helm/kims/values-production.example.yaml(main)- https://www.jenkins.io/doc/book/pipeline/getting-started/#defining-a-pipeline-in-scm
- https://www.jenkins.io/doc/book/pipeline/syntax/#parameters
- https://www.jenkins.io/doc/book/pipeline/syntax/#triggers
- https://plugins.jenkins.io/git/
- https://docs.docker.com/reference/cli/docker/buildx/build/
- https://helm.sh/docs/helm/helm_upgrade/
- https://helm.sh/docs/helm/helm_rollback/