Notes
How it is built
Jenkins has a controller and agents. The controller is the web interface: it holds jobs, schedules runs, stores results and loads plugins. Agents are the machines or containers that actually run the steps, chosen by labels like linux or docker. Almost every feature comes from a plugin. And Jenkins is self hosted: someone in the company installs, secures and updates it, which is a big difference from hosted CI.
- controller: web UI, jobs, schedules, plugins, results
- agents: machines or containers that run the build steps (labels: linux, docker, gpu)
- plugins: almost every feature (JUnit, Git, Docker, Allure)
- self-hosted: your team runs and updates it
Pipeline as code
Modern Jenkins jobs are pipelines defined in a Jenkinsfile in the repository, reviewed like any code. The declarative style starts with pipeline. Agent says where to run, here any agent labelled linux. Options add a thirty minute timeout. Triggers add a nightly run; H spreads the exact minute so not every job starts at once. Parameters add a drop down, here the environment, shown on the build with parameters button.
pipeline {
agent { label "linux" }
options { timeout(time: 30,
unit: "MINUTES") }
triggers { cron("H 2 * * *") }
parameters { choice(name: "ENV",
choices: ["local", "staging"]) }
stages { ... }
post { ... }
} Stages
Stages are the named boxes you see in the Jenkins interface. The first starts ShopRung in the background with its log saved, and waits for the health check. The tests stage has parallel branches: API and UI run at the same time on the same agent, each with its own command. Sh runs a shell command; dir changes folder. If a command exits with an error, the stage fails and turns red.
stage("Start ShopRung") { steps {
dir("shoprung") { sh """
nohup npm start > shop.log 2>&1 &
npx --yes wait-on@8 http-get://..."""
} } }
stage("Tests") { parallel {
stage("API") { steps {
sh "cd api-tests && pytest
--junitxml=results/api.xml" } }
stage("UI") { steps {
sh "cd e2e && npx playwright test" } } Credentials
Secrets live in Jenkins' credentials store, not in the Jenkinsfile. The credentials helper in an environment block binds one to variables: for a username and password credential, you get two variables ending in U S R and P S W, and Jenkins masks them in the console log. Tests read them as environment variables. Never print them, and never write them into reports.
environment {
ALICE = credentials("shoprung-alice")
}
// a "username with password"
// credential gives:
// ALICE_USR and ALICE_PSW
// Jenkins masks them in the log
never: echo $ALICE_PSW Post actions
Post actions run after the stages. Always runs whatever happened: the junit step reads every JUnit XML file and shows a test results page with trends across builds; archive artifacts keeps ShopRung's log and Playwright's test results with the build. Failure runs only when the build failed, a good place to notify the team. The junit step also marks the build unstable, shown yellow, when tests failed but the commands themselves ran.
post {
always {
junit "**/results/*.xml"
archiveArtifacts artifacts:
"shoprung/shop.log, **/test-
results/**", allowEmptyArchive:
true
}
failure { echo "notify the team" }
} Plugins for testers
Plugins testers use most: JUnit, for results, trends and the history of each test. HTML publisher, to show the Playwright report inside Jenkins. Allure, for an Allure report per build with history. A pipeline graph view for a visual picture of stages. And Docker pipeline, so a stage can run inside a container image with the right browsers installed, which keeps agents simple.
- JUnit: test results, trends, history of each test
- HTML Publisher: show the Playwright HTML report
- Allure: Allure report per build with history
- Pipeline Graph View / Blue Ocean: visual stages
- Docker Pipeline: agent { docker }
Reading a failed build
When a build is red, look in this order. The stage view shows which stage failed. The test result page lists failing tests with errors and stack traces, and each test's history shows since which build it fails, which often points straight at a commit. Then artifacts: the app log, traces and screenshots. The raw console output is the last resort. The changes page lists the commits in the build.
- 1 stage view: which stage went red?
- 2 Test Result: which tests, error, stack trace, history (failing since build #?)
- 3 artifacts: app log, traces, screenshots
- 4 console output: last resort
- 5 Changes: which commits
Versus GitHub Actions
Compared with GitHub Actions: Jenkins is self hosted, with a huge choice of plugins, can reach internal company systems easily, and uses Groovy based pipelines, but it needs care and updates. GitHub Actions is hosted next to the code, uses YAML and a marketplace of actions, and needs little upkeep. The concepts carry over directly: stages or jobs, parallel runs, secrets, artifacts and test reports.
- Jenkins: self-hosted, huge plugin choice, any network (internal systems), Groovy pipelines; needs upkeep
- GitHub Actions: hosted with the code, YAML, marketplace, little upkeep
- same concepts: stages/jobs, parallel, secrets, artifacts
Common mistakes
Jenkins mistakes. Jobs configured only by clicking in the UI, so nobody can review or restore them. Secrets echoed into the log. No junit step, so results exist only in console text. No timeout. Long lived agents full of old browsers and leftover processes, so builds behave differently on each machine; containers fix that. And running builds on the controller itself, which is slow and insecure.
- jobs configured only in the UI (not in Git)
- secrets echoed in the log
- no junit step: results only in the console
- no timeout on the pipeline
- agents full of old browsers and leftover processes
- everything on the controller
Say it like this
In the interview: a declarative Jenkinsfile in the repository. One stage starts the app and waits for its health check; API and UI tests run as parallel stages inside a Docker agent with the right browsers. Credentials come from the credentials store, and post always publishes JUnit results and the HTML report and archives logs and traces. A nightly cron trigger, a parameter for the environment, and timeouts on everything.
- "Declarative Jenkinsfile in the repo: a stage starts the app and waits on health, API and UI run
- as parallel stages in a Docker
- agent, credentials via credentials(), and post always
- publishes JUnit, the HTML report
- and archives logs and traces.
- Nightly cron, parameters for environment, timeouts."