Getting Started with Jenkins

Jul 17, 2024

Getting Started with Jenkins 🔧

Introduction to Jenkins

  • Comprehensive guide including both theory and practical labs.
  • Jenkins is a sought-after DevOps skill, and engineers can earn between $150,000 to $250,000 per year.
  • Jenkins is an automation platform that can build, test, and deploy software using pipelines.
  • Can automate a variety of tasks, including running Bash, Python scripts, and Ansible playbooks.
  • Provides a web GUI to create jobs and manage functionalities (source control, build actions, triggers).

Jenkins Infrastructure

  • Master Server: Controls pipelines and schedules builds to agents.
  • Agents: Execute jobs in their workspace.
  • Workflow example: Commit to a Git repo → Jenkins master triggers pipeline → Build distributed to an agent.
  • Types of Jenkins agents:
    • Permanent Node Agents: Standalone Linux/Windows servers configured to run Jenkins jobs.
      • Need Java installed and SSH configured.
    • Cloud Agents: Dynamically spun up (e.g., Docker, Kubernetes, AWS Fleet Manager).
      • Configured via agent templates (demonstrated with Docker in the lab).

Types of Jenkins Build Jobs

  • Freestyle Build Projects:
    • Simplest way to get started, like running shell scripts.
    • Easily managed through the GUI and plugins.
    • Executed by shell scripts; familiar with shell scripting or Linux command line is beneficial.
  • Pipelines:
    • Use Jenkins files written in Groovy syntax.
    • Common stages: Clone, Build, Test, Package, Deploy.
    • Jenkins files provide a way to specify what happens during the build in a structured manner.

Setting Up Jenkins

  • Installation options on the website: Direct installation on the OS, Docker, or Kubernetes.
  • Suggested method: Use Docker.
  • Summary of steps from the GitHub repository:
    1. Build the Docker image.
    2. Create a Docker network called jenkins.
    3. Launch the Docker container.
  • Detailed setup instructions and commands are provided in the repository (e.g., Dockerfile setup, commands to build and run Jenkins).

Jenkins Interface Overview

  • Main items in Jenkins UI:
    • Breadcrumbs: Navigation aid.
    • New Item: Create projects and pipelines.
    • People: Manage user accounts.
    • Build History: History of all jobs run.
    • Manage Jenkins: Main management section (agents setup, plugins, etc.).
    • My Views/New View: Organize jobs and their display.
    • Blue Ocean: Enhances CI/CD pipelines' UI.
  • Manage Jenkins sub-sections of interest:
    • Configure System: Global parameters for the Jenkins server.
    • Manage Plugins: Install and manage plugins.
    • Manage Nodes and Clouds: Setup agents and cloud services.
    • Security: Manage users and credentials.

Setting Up Jenkins Agents

  • Permanent Agents: Suitable for older setups, configured via SSH.
  • Cloud Agents: More modern approach using platforms like Docker, Kubernetes, AWS.
    • Example setup with Docker:
      • Install Docker plugins from Jenkins plugin manager.
      • Set Docker Cloud Details.
      • Create Docker Agent Templates specifying Docker images and other configurations.
      • Test with labels and verify builds.

Creating Jenkins Build Jobs

  • Freestyle Projects:
    • Easy to set up; use UI and plugins.
    • Basic workflows using shell scripts (example: `echo