1. Explain the difference between a declarative and imperative pipeline definition. Which approach would you recommend for a team maintaining multiple similar workflows?
Declarative pipelines (like Jenkins Declarative or GitLab CI YAML) define the desired end state in configuration files and are version-controlled, repeatable, and easier for teams to maintain. Imperative pipelines (like Jenkins Scripted Pipeline) use programming logic and offer more flexibility but can become harder to debug and maintain at scale. For teams with multiple similar workflows, declarative is recommended because it enforces consistency, reduces duplication through shared templates or anchors, and makes pipeline logic transparent and auditable in git history.
2. Design a CI/CD pipeline for a monorepo containing three independent services. How would you avoid rebuilding and redeploying services that have no code changes?
Use path-based filtering or change detection to trigger jobs only when files in a specific service directory are modified. Tools like git diff between commits identify which services changed, and conditional job execution (using when clauses in GitLab CI or stage conditions in GitHub Actions) prevents unnecessary builds. For example, in a monorepo with services/api, services/worker, and services/frontend, you would extract the diff set, check if each service path is affected, and conditionally trigger that service's build, test, and deploy stages, saving time and compute resources on unrelated changes.
3. Your pipeline has a flaky integration test that passes 95% of the time but fails randomly on external API timeouts. How would you handle this in your pipeline design?
Implement retry logic at the pipeline level (allow up to 3 retries for the integration test stage) combined with exponential backoff to handle transient failures without blocking the entire build. Additionally, isolate external API calls using mocks or test containers in earlier stages so the integration test only validates your service's contract, not the external system's reliability. If flakiness persists, mark the test as non-blocking in the main pipeline (allow it to fail without blocking deployment) and run it separately for visibility, then investigate root causes like timeout thresholds or resource contention in a dedicated diagnostic phase.
4. What are the trade-offs between running all tests in parallel versus running them in stages? How would you decide for your pipeline?
Parallel execution reduces total pipeline duration (faster feedback) but increases resource consumption and can mask test isolation issues or cause race conditions on shared infrastructure. Sequential or staged execution (unit tests, then integration, then e2e) uses fewer resources, provides clearer failure attribution, and allows early termination if unit tests fail. The decision depends on your resource budget, failure rate tolerance, and feedback requirements: fast-moving teams with ample CI resources typically parallelize aggressively, while resource-constrained environments use stratified stages, running only expensive stages (e2e) if cheaper stages pass.
5. Design the deployment stage of a pipeline for a service with zero-downtime requirements. What pipeline constructs would you use?
Use a multi-stage deployment pattern: first deploy to a canary environment (small traffic subset), validate health checks and metrics, then perform a gradual rollout (blue-green or rolling deployment) to production. In the pipeline, add a manual approval gate or automated promotion gate after canary validation, then trigger the production deployment with orchestration tools like Kubernetes or deployment platforms that handle traffic shifting. Conditional stages in your pipeline definition would validate smoke tests post-canary before proceeding to full rollout, and automated rollback triggers (monitoring for error rate spikes) would revert to the previous version if production deployment degrades service health.
6. Your team uses feature branches and mainline development. Design a pipeline strategy that prevents incomplete features from reaching production while still enabling frequent merges.
Use branch protection rules combined with pipeline gates: feature branches must pass all tests (unit, integration, linting) before PR approval, and only the main branch triggers the deployment pipeline to staging and production. Implement feature flags in your code so incomplete features can merge to main but remain hidden in production, allowing developers to toggle them on after full validation. The pipeline would have different stages for different branches: feature branches run fast tests only, merge to main triggers the full test suite, and only after main's tests pass does the deployment stage execute, ensuring main is always production-ready.
7. How would you design a pipeline stage that orchestrates multiple dependent jobs where job B cannot start until job A completes successfully? What mechanisms ensure this ordering?
Define explicit stage dependencies in your pipeline definition: in GitLab CI, use the 'stages' keyword to order stages sequentially (stage A before stage B), and GitLab automatically waits for all jobs in stage A to pass before starting stage B. In Jenkins, use pipeline sections or job triggers to chain builds, or in GitHub Actions, use 'needs' or job dependencies to specify that job B depends on job A. Within the same stage, use artifacts and 'dependencies' (GitLab) or 'artifact' upload/download (GitHub) to pass outputs from job A to job B, and the CI system enforces that job A must complete before job B accesses those artifacts.
8. Your pipeline produces Docker images that are pushed to a registry. Design a strategy for image versioning and cleanup to prevent registry bloat while ensuring reproducibility.
Tag images with both semantic versions (v1.2.3) and git commit SHAs (sha-abc1234) so each build is reproducible and traceable to its source code commit. Implement a retention policy in your registry (e.g., keep the last 50 images per branch, or delete images older than 30 days) and add a pipeline stage that runs periodically to prune untagged images and old feature-branch images. Store the image SHA in an artifact or environment variable during the build stage so downstream deployment stages reference the exact SHA, ensuring the image deployed to production matches the one that passed all tests, eliminating the 'latest' tag ambiguity.
9. Debug this scenario: a pipeline that works locally on developers' machines but fails in CI with 'dependency not found' errors during the build stage. What pipeline design practices would prevent this?
The local build likely has cached dependencies or implicit system libraries that the CI container lacks; design the pipeline to use a containerized build environment (Docker or Podman) with a FROM base image that matches production, ensuring all dependencies are explicitly declared in package files and installed in the pipeline. Add a 'dependency lock' file (package-lock.json, go.sum, Pipfile.lock) to version control so the exact dependency versions are reproducible across environments. The pipeline stage should perform a fresh clone and install (not reuse local cache), run a build log parser to flag unresolved dependencies, and fail fast with clear error messages; use the same build container locally and in CI by committing a Dockerfile or using a shared build image specification.
10. Design a pipeline notification strategy that alerts teams to failures without causing alert fatigue. What information would you include in notifications?
Implement tiered notifications: aggregate failures by severity (block vs. non-critical), notify only on job failures that affect deployment (not every flaky test retry), and include actionable details like the specific test that failed, the git commit SHA, and a direct link to the pipeline logs. Use notification channels appropriately: Slack for critical deployment blockers and PR feedback, email for detailed failure reports sent asynchronously, and dashboard summaries for trend analysis. Suppress notifications for expected failures (e.g., feature-branch flakes or approved manual pauses), and batch notifications from the same pipeline run to avoid multiple alerts for a single root cause, allowing teams to focus on actual issues.
11. A pipeline must enforce security scanning (SAST, dependency checks, secrets scanning) before code merges. Where in the pipeline would you place these stages, and how would you balance speed with security?
Place security scans as early as possible in the pipeline (after checkout, before unit tests) so developers get fast feedback on violations; run lightweight scans (secrets, basic linting) in pull request pipelines, and comprehensive scans (SAST, full dependency audits) only after PR approval or on merge to main. Design the pipeline to fail fast: if secrets are detected, block immediately without running further stages; for dependency vulnerabilities, distinguish between blockers (critical CVEs) and warnings (low-risk outdated libraries) to avoid unnecessary delays. Use caching for scan databases and tools to minimize stage duration, and integrate scan results into your code review system (comment on PRs with findings) so developers address issues before merge, reducing late-stage rejections.
12. Your organization is migrating from Jenkins to GitLab CI. Design a pipeline that works in both systems during the transition period. What abstraction strategies would you use?
Create a wrapper script (shell or Python) that abstracts environment variables and execution patterns, allowing the same build logic to run on both platforms; this script handles platform-specific differences like Jenkins environment variables (BUILD_NUMBER, WORKSPACE) versus GitLab CI variables (CI_PIPELINE_ID, CI_PROJECT_DIR). Store common build steps (compile, test, deploy) in a separate shell script that is called identically from both Jenkins (via Execute Shell) and GitLab CI (via script sections), making the core logic platform-agnostic. Define a gradual migration path where new projects use GitLab CI and old Jenkins jobs are migrated incrementally; use a shared artifact repository and consistent tagging schemes so both systems can retrieve and push the same build outputs, allowing them to coexist until the full cutover.



