Opscraft
CI/CD & build tooling

Jenkinsfile

Must-know10 lessons · 36 min · 3 tests ·

A Jenkinsfile defines a pipeline as code, stored and reviewed alongside the application. Interviews typically ask you to write or critique one on a whiteboard: build → test → scan → push → deploy to staging → approval → production, with parallel tests, credentials handled safely, and clean failure handling. This topic is a complete reference to declarative syntax plus the patterns that make pipelines fast, safe and maintainable.

Stage 2 · Core tools

Know these first

After this topic you can

  • Write declarative Jenkinsfiles with stages, parallelism and post steps
  • Handle credentials, approvals and environments
  • Structure pipelines with shared libraries

Lessons

  1. 1Declarative vs scripted pipelines 3 min read
    • Two syntaxes, one engine
    • Where a Jenkinsfile comes from
  2. 2The declarative skeleton, directive by directive 6 min read
    • options
    • parameters
    • environment
    • triggers
    • tools
    • post conditions
  3. 3Agents and workspaces 3 min read
    • Agent variants
    • agent none + per-stage agents
    • Workspaces
  4. 4Conditions, parallelism and resilience 5 min read
    • when
    • parallel
    • matrix
    • Resilience steps
  5. 5Credentials, environment and parameters in practice 3 min read
    • Binding credentials
    • Setting and passing values between stages
    • withEnv
  6. 6Approvals and promotion 3 min read
    • The input directive (preferred) vs input step
    • Promotion in a GitOps world
  7. 7Reports, artifacts and notifications 3 min read
  8. 8A complete production Jenkinsfile 3 min read
  9. 9Tooling, debugging and common errors 4 min read
    • Tools that save time
    • Common errors
    • Speeding up a slow pipeline
  10. 10Interview questions and model answers 3 min read
    • "Write a pipeline for build, test, staging deploy, approval and production deploy."
    • "Declarative or scripted?"
    • "How do you pass a value computed in one stage to a later stage?"
    • "Why put input outside an agent?"
    • "How do you stop two builds deploying to staging at the same time?"
    • "A security scan finds critical CVEs. How does the pipeline prevent a deploy?"
    • "What's the difference between failure, unstable and aborted in post?"