KKIMS on-site docs
Jenkins

The kims-site-build job

Create the kims-site-build Pipeline job in the environment's folder with its three String parameters defined up front (so the CMS does not get HTTP 400), set Jenkins URL, run the first build and read the result.

kims-site-build builds the public website from one published content version and deploys it to the website bucket. The CMS worker starts it after every publish; people start it by hand for the first build and for rebuilds. One job per environment folder.

Who does this: whoever creates jobs in KIMS's Jenkins. Our engineer gives the settings, runs the first build and checks it.

#Before you start

  • The folder (kims-production, or kims-uat) has kims-database-url and kims-site-env (Credentials).
  • The agent has Node.js 24, Chrome and 15 GB free disk (Agent).
  • The agent's IAM role can read the assets bucket, write the website bucket and invalidate the distribution (IAM).
  • The database is migrated and the content is loaded (Content load), for the first real build.

#Set Jenkins's own URL first

The site build stores a link to its Jenkins run (BUILD_URL) on the build record, and the CMS Builds screen shows it. Jenkins builds that link from its own configured URL.

  1. Manage Jenkins, System.
  2. Section Jenkins Location, field Jenkins URL: the address people and the CMS use, for example https://<JENKINS_HOST>/.
  3. Save.

Who does this: KIMS's Jenkins admin. It is usually already set; check it is the address the CMS pods will use, not localhost.

#Create the job

  1. Open the folder: <JENKINS_URL>/job/kims-production/ (UAT: kims-uat).
  2. New Item.
  3. Enter an item name: kims-site-build. Exactly this name: it is part of JENKINS_JOB_URL.
  4. Choose Pipeline. OK.
  5. Description: KIMS v2: build and deploy the public website (production). Started by the CMS.
  6. Tick This project is parameterized and add the three parameters as in Add the three parameters now.
  7. Triggers: leave everything unticked. The CMS starts this job.
  8. Pipeline, Definition: Pipeline script from SCM.
  9. SCM: Git. Repository URL: <KIMS_GIT_URL>. Credentials: the Git credential.
  10. Branch Specifier: */main for production, */uat for UAT. It must match KIMS_ENV in the folder's kims-site-env.
  11. Script Path: deploy/jenkins/Jenkinsfile.site.
  12. Lightweight checkout: leave ticked.
  13. Save.

The job's address is now:

Environment Job URL (this is JENKINS_JOB_URL)
Production https://<JENKINS_HOST>/job/kims-production/job/kims-site-build
UAT https://<JENKINS_HOST>/job/kims-uat/job/kims-site-build

It goes into the environment's Helm values as env.JENKINS_JOB_URL (Helm values), with no trailing slash.

#Add the three parameters now

Do this when you create the job, not later.

#Why: HTTP 400 until Jenkins knows them

A Pipeline job learns the parameters in its Jenkinsfile only when it runs for the first time. Until then the job has no parameters, and Jenkins answers the CMS's POST .../buildWithParameters with HTTP 400 (the job is not parameterized). The first publish then cannot start a build: the worker logs Jenkins answered HTTP 400 to POST /job/kims-production/job/kims-site-build/buildWithParameters and retries.

#How

Under This project is parameterized, Add Parameter, String Parameter, three times:

Name Default Value Description
PUBLISH_VERSION (empty) The published content version to build
CAUSE manual publish, retry, rebuild, platform or manual
TRIGGER_ACTOR (empty) Who asked, as "Name <email>"; empty for a publish

Leave Trim the string unticked. Names are case sensitive.

The other way is to press Build Now once and let that run fail: after it, Jenkins knows the parameters. Adding them by hand is cleaner, because a failed run in a folder that already has its credentials could start doing real work.

After the first real run, the Jenkinsfile's own definitions replace the ones typed here (they are the same).

#What the job does

Stage What runs Stops when
(implicit) Checkout SCM Jenkins checks out the branch Git not reachable
Check environment Loads kims-site-env into the environment, then deploy/jenkins/check-environment.sh "$KIMS_ENV" "$GIT_BRANCH" See The check environment stage
Install Deletes last run's gate-results.json and build-failure.json, records the start time, npm ci --no-audit --no-fund npm registry not reachable
Build and deploy Loads kims-site-env again, then node --import tsx scripts/site-build/run.mjs --version "$PUBLISH_VERSION" --cause "$CAUSE" --actor "$TRIGGER_ACTOR" Any build step or quality gate fails
(post, always) Archives gate-results.json and build-failure.json never

Settings fixed by the Jenkinsfile:

Setting Value Why
agent any any executor See the overview's warning
disableConcurrentBuilds() one run at a time; others queue Two builds at once would sync two sites into one bucket
timeout(90 minutes) A full build takes about 15 to 20 minutes
buildDiscarder 50 builds, artifacts of 20
timestamps() Needs the Timestamper plugin
DATABASE_URL from kims-database-url Masked in the log
NODE_OPTIONS --max-old-space-size=4096 The static build is memory bound
npm_config_cache ${JENKINS_HOME}/npm-cache Keeps the npm cache between builds. See the note below
Note

JENKINS_HOME is the controller's home path, also passed to builds on agents. On an agent, npm creates npm-cache at that same path. If the agent's user cannot create it (for example /var/lib/jenkins belongs to root on the agent), Install fails with EACCES. KIMS's admin can create the directory on the agent and give it to the agent's user. See Troubleshooting.

run.mjs then does the whole build: exports content version PUBLISH_VERSION from the database, exports the media manifest, writes the Google reviews feeds, builds every enabled language, runs the quality gates (any failure stops the build before anything is deployed), copies the referenced media from the assets bucket, syncs the build into the website bucket and deletes what the build no longer has, invalidates CloudFront, syncs the redirects KeyValueStore if one is set, and records the result in the site_builds table.

A build of a version older than the one already live is recorded as skipped and deploys nothing. A rebuild of the live version goes ahead.

#The check environment stage

Before anything is installed, the job compares the folder's settings with the branch:

KIMS_ENV in kims-site-env Branch the job built Result
production main Environment: production, branch: main, carries on
uat uat Environment: uat, branch: uat, carries on
production uat (or the reverse) Stops: This run is for production, which builds only from the 'main' branch, but it checked out 'uat'.
(missing) any Stops: No environment set. KIMS_ENV (site build) or the branch (platform) must say uat or production.
anything else any Stops: Unknown environment '<value>'. Use uat or production.
set Jenkins gave no branch Warns Jenkins did not say which branch it checked out ... and carries on

So production's website can never be built from UAT's code, nor UAT's settings applied from main.

#First run

Do this once the content is loaded (Website). Nothing is in the website bucket before it.

  1. Open <JENKINS_URL>/job/kims-production/job/kims-site-build/.
  2. Build with Parameters.
  3. PUBLISH_VERSION: 1 (the data bundle loads as published version 1). CAUSE: manual. TRIGGER_ACTOR: empty, or your name as Name <email>.
  4. Build.
  5. Open the run and follow Console Output.

It takes about 15 minutes on a suitable agent (about 20 on the local stand-in).

#What success looks like

  • Console shows Environment: production, branch: main early on, and ends with Finished: SUCCESS.
  • The run's page lists the archived gate-results.json. Open it: every gate has passed (Lighthouse included, with scores).
  • The CMS Builds screen shows the build, with each stage, and marks it live when done.
  • The website: open https://<WEBSITE_HOST>/, a few inner pages, their images, /kn/ and /hi/, /sitemap.xml and /robots.txt. On production robots.txt allows search engines and names the sitemap; on UAT it disallows everything.

Check the bucket from your machine if you have AWS access (AWS CLI):

bash
aws s3 ls s3://<WEBSITE_BUCKET>/ --region <AWS_REGION> | head
aws s3 ls s3://<WEBSITE_BUCKET>/ --recursive --summarize --region <AWS_REGION> | tail -2
bash
aws s3 ls s3://<WEBSITE_BUCKET>/ --region <AWS_REGION> | head
aws s3 ls s3://<WEBSITE_BUCKET>/ --recursive --summarize --region <AWS_REGION> | tail -2
powershell
aws s3 ls s3://<WEBSITE_BUCKET>/ --region <AWS_REGION> | Select-Object -First 10
aws s3 ls s3://<WEBSITE_BUCKET>/ --recursive --summarize --region <AWS_REGION> | Select-Object -Last 2

You should see index.html, the language folders and thousands of objects in Total Objects.

#If the first run is skipped

The console says the version is older than the live one. On a fresh environment that means PUBLISH_VERSION was wrong; check the newest published version with the CMS (Publishing screen) and build that.

#Starting it by hand later

  • Rebuild the live version (for example after a CloudFront or bucket change): Build with Parameters, PUBLISH_VERSION the live version, CAUSE rebuild.
  • From the CMS: the Builds screen's Retry and Rebuild buttons (Admin only) do the same through the API, with TRIGGER_ACTOR filled in.

#Let the CMS start it

The CMS needs a Jenkins user allowed to build this job, and that user's API token: The CMS user and API token. Test the trigger there with curl before the first publish.

#If it goes wrong

Where What you see Likely cause What to do
CMS worker log Jenkins answered HTTP 400 to POST .../buildWithParameters The job has no parameters yet Add the three parameters now
CMS worker log HTTP 401 / HTTP 403 Wrong token, or the CMS user lacks Build on this job API token
CMS worker log HTTP 404 JENKINS_JOB_URL wrong (missing the folder part, a typo) Must be .../job/<folder>/job/kims-site-build
Check environment Could not find credentials entry with ID 'kims-site-env' Credential missing in this folder Credentials
Check environment This run is for ..., which builds only from ... Branch and KIMS_ENV disagree Fix one of them
Install EACCES ... npm-cache The agent's user cannot create ${JENKINS_HOME}/npm-cache Troubleshooting
Install node: not found / npm: not found Ran on an agent without Node Troubleshooting
Build and deploy Lighthouse gate fails, No Chrome installations found No Chrome on the agent Agent
Build and deploy AccessDenied on PutObject / CreateInvalidation The agent's IAM role lacks the permission IAM
Build and deploy A database connection error kims-database-url wrong, or the agent cannot reach RDS on 5432 Networking

More in Jenkins troubleshooting.

#Sources

Built 2026-11-29. Commands are shown for the system picked at the top; every block has all three.