Skip to the page

CI/CD for developers · mid

Jenkins and GitHub Actions pipelines as code

Both tools keep the pipeline in the repository. Know the shape of a declarative Jenkinsfile and the trade-offs between self-hosted Jenkins and hosted GitHub Actions.

The notes

What you must know

  • Jenkinsfile shape: pipeline { agent ...; options { timeout(...); disableConcurrentBuilds(); buildDiscarder(...) }; stages { ... }; post { ... } }, run as a multibranch pipeline so each branch and pull request gets its own run.
  • Build and test stage: sh 'mvn -B verify', with post { always { junit 'target/surefire-reports/*.xml' } } so failed tests still publish their reports.
  • Image stage with when { branch 'main' }: build and tag $ECR_REPO:$GIT_COMMIT, log in with aws ecr get-login-password | docker login --username AWS --password-stdin, push. Deploy staging stage: helm upgrade --install with values-staging.yaml, --set image.tag=$GIT_COMMIT and --wait.
  • Production stage: an input step for approval, and the same image. post blocks for notifications and cleanup.
  • Credentials: the Jenkins credentials store with withCredentials (masked in logs). Better, agents with cloud roles so no stored keys.
  • Jenkins strengths: self-hosted and fully controlled, works with any Git server, runs inside private networks (banks, client networks), huge plugin choice. Pains: plugin upgrades and conflicts, the controller as a single point of failure, security patching, configuration drift.
  • GitHub Actions: workflows in .github/workflows, hosted runners with no server to run, a large marketplace, reusable workflows and composite actions (like Jenkins shared libraries), OIDC to cloud. Pains: minutes cost, private network access needs self-hosted runners, third-party actions are supply-chain risk, so pin them to a commit SHA.
  • Choose by where code lives, network access needs, team skills and who maintains it.

The red pen

Common traps: mistake → fix

  • Mistake: Jenkins is outdated and Actions is always better

    Fix: Jenkins fits private networks and full control. The choice depends on the context.

  • Mistake: Credentials in the Jenkinsfile are fine if the repo is private

    Fix: Use the credentials store or roles. Repos get cloned and shared.

  • Mistake: A third-party action by tag is safe

    Fix: Tags can move. Pin to a full commit SHA.

Easy to hard

Questions interviewers ask, easy to hard

  1. Write the skeleton of a Jenkinsfile for a Spring Boot service.
  2. Why publish test reports in a post always block?
  3. How does a Jenkins pipeline push to ECR securely?
  4. Jenkins or GitHub Actions for a new team? What do you ask first?
  5. How do you share pipeline steps across ten services in each tool?

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview