Index
| # | Level | Assignment |
|---|---|---|
| 1 | ๐ข | Run Jenkins in Docker and map JENKINS_HOME |
| 2 | ๐ข | Your first declarative pipeline from SCM |
| 3 | ๐ข | Parameters, environment and when |
| 4 | ๐ข | Post conditions and build results |
| 5 | ๐ข | Credentials binding and masking |
| 6 | ๐ข | Add an inbound agent and empty the controller |
| 7 | ๐ข | JUnit reports and archived artifacts |
| 8 | ๐ข | Cron triggers, H, and the REST API |
| 9 | ๐ข | Stash, unstash and multiple agents |
| 10 | ๐ข | Jenkins CLI and the declarative linter |
| 11 | ๐ก | Parallel stages and fail-fast |
| 12 | ๐ก | Matrix builds with exclusions |
| 13 | ๐ก | Approval gates with input and no held agent |
| 14 | ๐ก | Multibranch pipeline with PR discovery and webhooks |
| 15 | ๐ก | Your first shared library |
| 16 | ๐ก | Controller image with pinned plugins |
| 17 | ๐ก | Configure a controller entirely with JCasC |
| 18 | ๐ก | Kubernetes agents with multi-container pods |
| 19 | ๐ก | SonarQube quality gate |
| 20 | ๐ก | Folder-scoped credentials and matrix authorization |
| 21 | ๐ด | Seed every job with Job DSL from JCasC |
| 22 | ๐ด | Unit test a shared library with JenkinsPipelineUnit |
| 23 | ๐ด | CPS deep dive: break it and fix it |
| 24 | ๐ด | Backup, disaster recovery and an LTS upgrade drill |
| 25 | ๐ด | Secure supply-chain pipeline: build, scan, sign, deploy by digest |
๐ข Beginner
Assignment 1. Run Jenkins in Docker and map JENKINS_HOME ๐ข
Objective: Get a controller running and understand where its state lives.
Tasks
- Create a named volume and run
jenkins/jenkins:lts-jdk21with ports 8080 and the volume mounted at/var/jenkins_home. - Read the initial admin password from the container and finish the setup wizard with the suggested plugins.
- List the top level of
/var/jenkins_homeand write one line describing each of:config.xml,jobs/,plugins/,secrets/,users/,nodes/. - Create a Freestyle job that runs
echo hello, build it, and find itslogfile on disk. - Delete and recreate the container with the same volume; confirm the job and its build survive.
Expected outcome / acceptance criteria
- Jenkins reachable at
http://localhost:8080after the container is recreated, with the job and build history intact. - A short note mapping each directory to its purpose, including why
secrets/is the most sensitive.
Hints
docker volume create jenkins_home, docker run -d --name jenkins -p 8080:8080 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts-jdk21, docker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword. Build logs are in jobs/<job>/builds/<n>/log.
Bonus: Find the job's config.xml and change the echo text directly in the file, then use Manage Jenkins > Reload Configuration from Disk and run it again.
Assignment 2. Your first declarative pipeline from SCM ๐ข
Objective: Move from UI-configured jobs to a Jenkinsfile in Git.
Tasks
- Create a GitHub repo with a small app (any language) and a
Jenkinsfilewith three stages: Checkout info, Build, Test. - In the Checkout info stage, print
GIT_COMMIT,GIT_BRANCH,BUILD_NUMBERandWORKSPACE. - Create a Pipeline job using "Pipeline script from SCM" pointing at the repo.
- Break the Test stage on purpose (
exit 1), observe the result, then fix it. - Open the Pipeline Syntax page and generate a
shstep withreturnStdout.
Expected outcome / acceptance criteria
- A green build with three stages visible in the stage view or Pipeline Graph View.
- A red build showing exactly which stage failed and the exit code.
Hints
pipeline {
agent any
stages {
stage('Checkout info') { steps { sh 'echo "$GIT_COMMIT $GIT_BRANCH $BUILD_NUMBER $WORKSPACE"' } }
stage('Build') { steps { sh 'echo building' } }
stage('Test') { steps { sh 'echo testing' } }
}
}Bonus: Add options { timestamps(); timeout(time: 10, unit: 'MINUTES') } and buildDiscarder(logRotator(numToKeepStr: '10')).
Assignment 3. Parameters, environment and when ๐ข
Objective: Make a pipeline configurable and conditional.
Tasks
- Add parameters:
choiceENV(dev, staging, prod),booleanParamRUN_SMOKE,stringVERSION. - Add a pipeline-level
environmentwithAPP_NAMEand a stage-levelenvironmentthat overrides it. - Add a stage that runs only when
params.RUN_SMOKEis true and one that runs only whenENV == 'prod'. - Run the job with three different parameter combinations.
- Print
params.RUN_SMOKEandenv.RUN_SMOKEand explain the type difference.
Expected outcome / acceptance criteria
- Skipped stages are shown as skipped, not failed.
- You can explain why
if (env.RUN_SMOKE)is truthy even when the value is'false'.
Hints
when { expression { params.RUN_SMOKE } }, when { environment name: 'ENV', value: 'prod' }. The first run after adding parameters registers them; the "Build with Parameters" button appears afterwards.
Bonus: Add when { beforeAgent true; ... } to a stage with its own agent and confirm no agent is allocated when it is skipped.
Assignment 4. Post conditions and build results ๐ข
Objective: Control what happens after success, failure and everything in between.
Tasks
- Add a pipeline-level
postwithalways,success,failure,unstable,fixed,regressionandcleanup, each printing its name. - Produce each result: SUCCESS, FAILURE (
error()), UNSTABLE (unstable()), ABORTED (click Abort during asleep 60). - Run FAILURE then SUCCESS to trigger
fixed, and SUCCESS then FAILURE to triggerregression. - Use
catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE')on one stage and observe the colours. - Record the order in which
postconditions fired.
Expected outcome / acceptance criteria
- A table of the five results with the post blocks that fired for each.
cleanupfires last every time.
Hints
Order is always, changed, fixed, regression, aborted, failure, success, unstable, unsuccessful, cleanup.
Bonus: Add a stage-level post and show it runs before the pipeline-level one.
Assignment 5. Credentials binding and masking ๐ข
Objective: Use secrets without leaking them.
Tasks
- Create credentials: secret text
demo-token, username/passworddemo-user, secret filedemo-file. - Bind
demo-userwithenvironment { CREDS = credentials('demo-user') }and printCREDS_USRand the length ofCREDS_PSW. - Bind all three with
withCredentialsin one stage. - Write one
shstep with double quotes interpolating the secret and read the warning Jenkins prints; rewrite it with single quotes. - Echo the token base64-encoded and observe that masking does not catch it. Then delete that build.
Expected outcome / acceptance criteria
- The plain secret is shown as
****in the log. - You can explain why masking is a convenience, not a security control.
Hints
withCredentials([string(credentialsId: 'demo-token', variable: 'TOKEN'),
file(credentialsId: 'demo-file', variable: 'CFG')]) {
sh 'echo "token length: ${#TOKEN}"; wc -c "$CFG"'
}Bonus: Move the credentials into a folder and prove a job outside the folder gets Could not find credentials entry with ID.
Assignment 6. Add an inbound agent and empty the controller ๐ข
Objective: Run builds on an agent, never on the controller.
Tasks
- Create a permanent node
docker-agent-1, labellinux docker, launch method "Launch agent by connecting it to the controller", remote root/home/jenkins/agent. - Start
jenkins/inbound-agent:latest-jdk21with-webSocket, the URL, secret and name. - Set the built-in node to 0 executors.
- Change your pipeline to
agent { label 'linux' }and confirmNODE_NAME. - Stop the agent container while a build runs and read the error.
Expected outcome / acceptance criteria
- Builds run on
docker-agent-1; the built-in node shows 0 executors. - You saved the error text from the killed agent and can explain it.
Hints
docker run -d --name agent1 --network <jenkins-network> jenkins/inbound-agent:latest-jdk21 -url http://jenkins:8080/ -webSocket -secret <secret> -name docker-agent-1 -workDir /home/jenkins/agent. Put both containers on the same user-defined Docker network so jenkins resolves.
Bonus: Set the node to EXCLUSIVE mode and show that a job with agent any no longer runs there.
Assignment 7. JUnit reports and archived artifacts ๐ข
Objective: Publish test results and keep build outputs.
Tasks
- Use a Node or Maven project that produces JUnit XML (
jest-junitor Surefire). - Publish results in
post { always { junit ... } }. - Make one test fail and observe UNSTABLE vs FAILURE depending on whether the test command fails the step.
- Archive the build output with
archiveArtifacts artifacts: 'dist/**', fingerprint: true. - Configure
buildDiscarderto keep artifacts for only the last 3 builds.
Expected outcome / acceptance criteria
- A test result trend graph after 3+ builds.
- Artifacts downloadable from the build page and removed for older builds.
Hints
buildDiscarder(logRotator(numToKeepStr: '20', artifactNumToKeepStr: '3')). If npm test fails the step, the build is FAILURE; to get UNSTABLE, run tests with returnStatus: true and let junit set the result.
Bonus: Add allowEmptyResults: false and show the build fails when the report path is wrong.
Assignment 8. Cron triggers, H, and the REST API ๐ข
Objective: Schedule builds and control Jenkins from scripts.
Tasks
- Add
triggers { cron('H/5 * * * *') }and observe the actual minutes it runs. - Generate an API token for your user.
- Trigger a parameterized build with
curland capture the queue item URL from theLocationheader. - Poll the queue item until it has a build number, then fetch
consoleTextof that build. - Fetch the last 5 build results of the job with a
treequery.
Expected outcome / acceptance criteria
- A shell script that triggers a build and prints its final result.
- You can explain why
Hspreads load.
Hints
curl -s -X POST -u user:$TOKEN "$URL/job/app/buildWithParameters?ENV=dev" -D - | grep -i location, then $QUEUE/api/json?tree=executable[number,url], then $URL/job/app/<n>/api/json?tree=result,building.
Bonus: Use /job/app/api/json?tree=builds[number,result,duration]{0,5} to get only the latest 5.
Assignment 9. Stash, unstash and multiple agents ๐ข
Objective: Move small files between stages on different agents.
Tasks
- Use
agent noneand two stages on different agents (two labels, or two Docker agent images). - Stage 1 builds a file (
dist/app.txtwith the build number) and stashes it. - Stage 2 unstashes it and prints it.
- Try to read the file in stage 2 without
unstashand record the error. - Explain where stashes are stored and why large stashes are a problem.
Expected outcome / acceptance criteria
- Stage 2 prints the content created by stage 1 on another agent.
Hints
stash name: 'dist', includes: 'dist/**' and unstash 'dist'. Stashes are stored on the controller and deleted at the end of the build unless preserveStashes is set.
Bonus: Replace the two agents with nested stages under one parent agent and remove the stash entirely.
Assignment 10. Jenkins CLI and the declarative linter ๐ข
Objective: Administer Jenkins and validate pipelines from the terminal.
Tasks
- Download
jenkins-cli.jarfrom your controller. - Run
who-am-i,list-jobs,list-pluginswith-authand-webSocket. - Validate a Jenkinsfile with
declarative-linter, then introducestep {}instead ofsteps {}and validate again. - Validate the same file via
curlto/pipeline-model-converter/validate. - Trigger a build with
build -f -vand watch the log stream.
Expected outcome / acceptance criteria
- A pre-commit hook or Makefile target that lints the Jenkinsfile before pushing.
Hints
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:$TOKEN -webSocket declarative-linter < Jenkinsfile.
Bonus: Run safe-restart from the CLI while a build is running and observe that Jenkins waits.
๐ก Intermediate
Assignment 11. Parallel stages and fail-fast ๐ก
Objective: Cut pipeline wall time with parallelism.
Tasks
- Create four check stages that sleep 30, 45, 60 and 20 seconds; run them sequentially and record the total time.
- Put them under one
parallelblock and record the time again. - Make the 20-second one fail; compare behaviour with and without
failFast true. - Give one parallel branch its own agent and explain the workspace implications.
- Generate a dynamic
parallelmap inscript {}from a list of service names.
Expected outcome / acceptance criteria
- Wall time drops to roughly the slowest branch.
- With
failFast, the remaining branches show as aborted.
Hints
In loops, copy the loop variable before capturing it in the closure: def svc = s; branches[svc] = { ... }.
Bonus: Use options { parallelsAlwaysFailFast() } at pipeline level instead of per stage.
Assignment 12. Matrix builds with exclusions ๐ก
Objective: Test across versions without copy-pasting stages.
Tasks
- Create a
matrixwith axesNODE_VERSION(18, 20, 22) andOS(linux, alpine) using container images per combination. - Exclude
18onalpine. - Publish JUnit results per cell with a unique report name.
- Make one cell fail and confirm the others still finish (no fail-fast).
- Count cells and explain how the matrix grows.
Expected outcome / acceptance criteria
- Five cells, named by axis values in the UI.
Hints
In the cell, choose an image with agent { docker { image "node:${NODE_VERSION}${OS == 'alpine' ? '-alpine' : ''}" } } on a Docker agent, or a Kubernetes pod template with the image interpolated.
Bonus: Add a third axis and observe when the pipeline becomes unwieldy; explain the Method code too large risk.
Assignment 13. Approval gates with input and no held agent ๐ก
Objective: Implement production approvals the right way.
Tasks
- Write a pipeline with
agent none, a Build stage with an agent, an Approve stage using theinputdirective, and a Deploy stage with an agent. - Restrict
submitterto a user or group and capturesubmitterParameter. - Add a stage-level
timeoutof 15 minutes on the approval. - While the build waits, confirm no executor is busy (or no agent pod exists on Kubernetes).
- Repeat with the
inputstep inside the Build stage's agent and compare executor usage.
Expected outcome / acceptance criteria
- With the directive, 0 executors are used during the wait; with the step, 1 is.
- An unauthorised user cannot approve.
Hints
input { message 'Deploy?'; ok 'Ship it'; submitter 'release-managers'; submitterParameter 'APPROVER' }. Check Build Executor Status while waiting.
Bonus: Add milestone() before and after the approval and show that approving an older build is impossible once a newer one passed.
Assignment 14. Multibranch pipeline with PR discovery and webhooks ๐ก
Objective: Build every branch and PR automatically.
Tasks
- Create a Multibranch Pipeline with the GitHub branch source.
- Configure discovery: branches excluding PR branches, PRs merged with target.
- Configure a webhook (ngrok or a public Jenkins) to
/github-webhook/. - Open a PR and confirm a
PR-<n>job builds within seconds; check the commit status on GitHub. - Add
when { branch 'main' }to a deploy stage and confirm PR builds skip it. - Delete the branch and observe the orphaned item strategy.
Expected outcome / acceptance criteria
- Webhook delivery shows HTTP 200; build cause is a push or PR event, not indexing.
- PR status check visible on GitHub.
Hints
Trailing slash on /github-webhook/ matters. Use Scan Repository Log and Multibranch Pipeline Events to debug.
Bonus: Add tag discovery with a build strategy for tags newer than 1 day and release on v* tags.
Assignment 15. Your first shared library ๐ก
Objective: Extract reusable pipeline logic into a versioned library.
Tasks
- Create a repo with
vars/greet.groovy(acall(Map)step),src/org/demo/Semver.groovy(a class that bumps versions) andresources/hello.sh. - Configure it as a global library named
demo-libwith default versionv1. - Use all three from a Jenkinsfile: the step, the class via
import, and the script vialibraryResource. - Add
vars/greet.txtand find it in the Global Variables Reference. - Release
v1.1.0, movev1, and confirm pipelines pick up the change without edits.
Expected outcome / acceptance criteria
- Build log shows
Loading library demo-lib@v1. - Rollback by moving the tag back works.
Hints
@Library('demo-lib@v1') import org.demo.Semver then greet(name: 'Shack'), Semver.bumpMinor('1.4.2'), writeFile file: 'hello.sh', text: libraryResource('hello.sh').
Bonus: Configure the same repo as a folder-level library and show that a method needing approval is blocked there but works in the global (trusted) one.
Assignment 16. Controller image with pinned plugins ๐ก
Objective: Make plugin installation reproducible.
Tasks
- Export your installed plugins as
name:versionintoplugins.txtusing the REST API andjq. - Write a Dockerfile
FROM jenkins/jenkins:<pinned-lts>-jdk21that installs them withjenkins-plugin-cli. - Build the image and start it with an empty volume; confirm the same plugin set.
- Run
jenkins-plugin-cli --available-updates --output txtto produce an update diff. - Remove one plugin that others depend on and read the error.
Expected outcome / acceptance criteria
- Two controllers built from the same image have identical plugin lists.
- A written plugin update procedure (staging, smoke test, rollback image).
Hints
curl -s -u admin:$T "$URL/pluginManager/api/json?depth=1&tree=plugins[shortName,version]" | jq -r '.plugins[] | "\(.shortName):\(.version)"' | sort > plugins.txt.
Bonus: Add --view-security-warnings to the build and fail the image build if any warnings are reported.
Assignment 17. Configure a controller entirely with JCasC ๐ก
Objective: Treat Jenkins configuration as code.
Tasks
- Add
configuration-as-codeto your image and setCASC_JENKINS_CONFIG. - Write
jenkins.yamlwith: system message, 0 executors, local security realm with two users, matrix authorization, one secret text credential from an env var, a global library, andunclassified.location.url. - Start with
-Djenkins.install.runSetupWizard=falseand verify every setting. - Change a setting in the UI, reload JCasC, and observe the revert.
- Introduce a typo in an attribute name and capture the
ConfiguratorException.
Expected outcome / acceptance criteria
- A fresh container comes up fully configured with no manual steps.
- No secret values exist in Git.
Hints
Use Manage Jenkins > Configuration as Code > View Configuration on a hand-configured instance as a starting point. Secrets via ${VAR} resolve from environment variables or /run/secrets/VAR.
Bonus: Add a CI job that boots the image with the YAML and fails if the log contains ConfiguratorException.
Assignment 18. Kubernetes agents with multi-container pods ๐ก
Objective: Run builds in ephemeral pods.
Tasks
- Install Jenkins on kind (Helm chart or manifests) and configure the kubernetes cloud with WebSocket.
- Create an agent namespace with RBAC for the controller's service account.
- Write a pod template with
mavenandnodecontainers (sleep infinity) and run steps in each withcontainer(). - Show that a file written in one container is visible in the other.
- Set
podRetentiontoonFailure, fail a build, inspect the retained pod, then revert.
Expected outcome / acceptance criteria
- A new pod per build, deleted after success.
kubectl -n <agents-ns> get pods -wshows the lifecycle.
Hints
agent { kubernetes { yamlFile 'ci/pod.yaml'; defaultContainer 'maven' } }. If the build hangs at Waiting for agent to connect, check the jnlp container logs and the jenkinsUrl.
Bonus: Add a ResourceQuota to the agent namespace and observe what happens when builds exceed it.
Assignment 19. SonarQube quality gate ๐ก
Objective: Block merges on code quality.
Tasks
- Run SonarQube (container or in cluster) and generate an analysis token.
- Configure the SonarQube server in Jenkins (UI or JCasC) with the token credential.
- Add
withSonarQubeEnvanalysis and awaitForQualityGate abortPipeline: truestage with a timeout. - Configure the SonarQube webhook to
/sonarqube-webhook/. - Create a custom gate that fails, run the pipeline, then restore the default gate.
Expected outcome / acceptance criteria
- The quality gate stage passes quickly (seconds after analysis) with the webhook, and times out without it.
- A failing gate aborts the build.
Hints
Without the webhook, waitForQualityGate waits until the timeout. Coverage must be generated before analysis (lcov.info for JS, JaCoCo XML for Java).
Bonus: Run the gate step outside any agent and explain the saving.
Assignment 20. Folder-scoped credentials and matrix authorization ๐ก
Objective: Make one controller safe for two teams.
Tasks
- Create folders
team-aandteam-b, each with a job and a credential nameddeploy-key. - Use project-based matrix authorization:
team-a-devscan build and configure inteam-aonly; same for team B. - Prove a team A job cannot bind team B's credential, and a team A user cannot see team B's folder.
- Remove
Run/Replayfrom developers and explain why. - Check effective permissions with
/whoAmI/for a test user.
Expected outcome / acceptance criteria
- A permission matrix document and screenshots or logs of the denied attempts.
Hints
Use the Matrix Authorization Strategy plugin's "Project-based Matrix Authorization Strategy", then enable "Enable project-based security" on each folder.
Bonus: Express the whole setup in JCasC and Job DSL (authorization { permission(...) } on folders).
๐ด Advanced
Assignment 21. Seed every job with Job DSL from JCasC ๐ด
Objective: Make the controller fully disposable.
Tasks
- Create a
teams.yamllisting three teams with their GitHub repos. - Write a Job DSL script that creates a folder per team and a multibranch pipeline per repo with GitHub branch source, PR discovery and an orphaned item strategy.
- Load the script from JCasC
jobs:. - Destroy the controller volume, redeploy, and confirm all jobs return and re-index on their own.
- Remove a team from the YAML, reload, and handle the removed jobs deliberately.
Expected outcome / acceptance criteria
- Recreating the controller from scratch restores every folder and job in under 10 minutes.
- No job is created by hand.
Hints
Use your controller's Job DSL API viewer (/plugin/job-dsl/api-viewer/index.html) for the exact dynamic DSL of github branch sources. Variables like ${GITHUB_ORG} are substituted by JCasC before the DSL runs.
Bonus: Run the same Job DSL in a seed job triggered by changes to the platform repo, with removedJobAction('DELETE').
Assignment 22. Unit test a shared library with JenkinsPipelineUnit ๐ด
Objective: Treat the library as production code with tests and CI.
Tasks
- Add a Gradle build to your library with JenkinsPipelineUnit and JUnit 5.
- Write tests for a
vars/step: mocksh,withCredentialsandcontainer, assert the exact command and that a missing argument callserror. - Write tests for a
src/class without mocks. - Add a Jenkinsfile to the library repo that runs the tests on every PR.
- Add a staging integration test: a real pipeline on a test folder that loads the PR branch of the library.
Expected outcome / acceptance criteria
./gradlew testpasses locally and in Jenkins; a broken step fails the PR.- The release procedure (tag, move
v1) is documented in the library README.
Hints
Extend BasePipelineTest, call helper.registerAllowedMethod('sh', [Map]) { m -> commands << m.script }, load with loadScript('vars/trivyScan.groovy'). Print printCallStack() while writing tests.
Bonus: Generate the vars/*.txt docs from code comments during the library build.
Assignment 23. CPS deep dive: break it and fix it ๐ด
Objective: Understand how pipeline Groovy really executes.
Tasks
- Write a pipeline that triggers
NotSerializableExceptionwith a regexMatcherheld across anecho; fix it with@NonCPS. - Trigger the same exception with
JsonSlurperand fix it withreadJSON. - Write a
@NonCPSmethod that callsechoand document the actual behaviour. - Run a Groovy loop that builds a 50,000-element list and observe controller CPU; reimplement the work in
shwithjqorawkand compare. - Restart the controller mid-build (with a long
shstep running) and observe resume behaviour withMAX_SURVIVABILITYvsPERFORMANCE_OPTIMIZED.
Expected outcome / acceptance criteria
- A write-up explaining CPS, serialization,
@NonCPSrules and durability with your own logs as evidence.
Hints
options { durabilityHint('PERFORMANCE_OPTIMIZED') }. Use /threadDump during the heavy Groovy loop to find the CPS VM thread for the build.
Bonus: Trigger Method code too large! with a generated Jenkinsfile and fix it with library extraction.
Assignment 24. Backup, disaster recovery and an LTS upgrade drill ๐ด
Objective: Prove you can recover and upgrade Jenkins without drama.
Tasks
- Write a backup script (or Kubernetes CronJob) that archives
JENKINS_HOMEexcludingworkspace/,caches/and exploded plugins, and uploads it to object storage. - Destroy the controller and its volume; restore into a new instance and verify credentials decrypt and build history is present. Time it.
- Repeat the restore without
secrets/and record what breaks. - Upgrade the restored instance to the next LTS: update the base image, regenerate plugin versions with
--jenkins-version, run smoke pipelines. - Roll back to the previous image and backup, and document what is and is not reversible.
Expected outcome / acceptance criteria
- A runbook with measured RTO and RPO, tested end to end.
Hints
tar --exclude='./workspace' --exclude='./caches' --exclude='./plugins/*/' -czf jenkins-home.tgz -C /var/jenkins_home .. Credentials failing to decrypt after restore means secrets/master.key or secrets/hudson.util.Secret is missing.
Bonus: Use Velero with CSI snapshots for the same drill and compare speed.
Assignment 25. Secure supply-chain pipeline: build, scan, sign, deploy by digest ๐ด
Objective: Combine everything into a pipeline you would defend in a security review.
Tasks
- Multibranch pipeline on Kubernetes agents, loading your shared library by tag.
- Build the image daemonless (Kaniko or BuildKit) into a tarball; scan with Trivy (fail on fixable HIGH/CRITICAL) and generate an SBOM (
trivy image --format cyclonedx). - Push only from
main; capture the digest; sign it with cosign using a key from a KMS or Vault, and attach the SBOM as an attestation. - Deploy to dev by digest with a dedicated service account; require a group-restricted
inputfor prod; enforce signatures in prod with KyvernoverifyImages. - Show that an unsigned image applied manually to prod is rejected by the cluster.
Expected outcome / acceptance criteria
- Every prod pod runs a signed image digest built and scanned by the pipeline.
- Bypassing Jenkins does not bypass the policy.
Hints
cosign sign --key awskms:///alias/cosign <repo>@<digest>, cosign attest --predicate sbom.json --type cyclonedx --key ... <repo>@<digest>. Run cosign in its own container in the pod template.
Bonus: Replace the kubectl prod deploy with a commit to a GitOps repo watched by Argo CD, so Jenkins holds no prod cluster credentials.