Opscraft
Jenkins · Lesson 8 of 11 · 3 min read

Designing CI/CD with Jenkins

A reference flow

Enlarge diagramlint + testsSAST, secretsbuild imageKanikoimage scanTrivystatus toGitHubpush to ECRtag = git SHAupdate GitOpsrepostaging overlayFlux: stagingsmoke testsapprovalrestricted inputFlux: prodsame tagPull requestMerge to main
Figure 1. A reference CI/CD flow with Jenkins and GitOps. Jenkins builds and writes to Git; Flux, inside the cluster, does the deploying.
Swipe sideways to see all of it, or tap to open it full screen.

On a pull request, Jenkins runs the checks, builds and scans the image, and reports a status back to GitHub. On a merge to main, it pushes the image tagged with the git SHA to ECR and updates the GitOps repo. Flux deploys to staging, a restricted approver promotes the same tag to production, and post-deploy checks can roll it back automatically.

Principles to state explicitly:

  • Build once, promote the same artifact (same image digest) through environments — never rebuild for prod.
  • Immutable, traceable versions — git SHA tags, never latest.
  • Shift-left quality and security gates — unit tests, SonarQube quality gate (waitForQualityGate), Trivy, dependency scanning, policy checks (conftest).
  • Separation of CI and CD in GitOps — Jenkins builds and updates Git; Flux (in the cluster) pulls and applies. Jenkins doesn't need cluster-admin credentials, which shrinks the blast radius if Jenkins is compromised.
  • Fast feedback — PR builds under ~10 minutes; slower suites nightly.
  • Notifications to the owning team (Slack) on failure, with links.
Enlarge diagramJenkins (CI)builds, tests, pushesGitOps repodesired stateFlux (CD)in the cluster, pullscommitpull
Figure 2. Splitting CI from CD: Jenkins never needs cluster credentials. A compromised Jenkins can change Git, which is reviewed and audited, but cannot touch the cluster directly.
Swipe sideways to see all of it, or tap to open it full screen.

Shared libraries as a platform product

With dozens of services, standardise pipelines in a shared library so each repo's Jenkinsfile is a few lines (standardPipeline(language: 'java', service: 'orders')). The platform team versions the library, tests it, and rolls improvements to every team — a central lever for security gates and consistency. (Covered in depth in the Groovy topic.)