CI/CD Pipelines with Jenkins or GitHub Actions

Chapter 4
Jenkins Fundamentals and Administration

Diploma in DevOps
CI/CD Pipelines with Jenkins or GitHub Actions   •   Diploma

Jenkins Fundamentals and Administration

Introduction and Context

Jenkins is an open-source automation server used to implement continuous integration (CI), continuous delivery (CD), and related software-delivery activities. It coordinates events such as source-code changes, executes automated jobs, collects results, publishes artifacts, and communicates status to development and operations teams.

Jenkins is not itself a deployment strategy or a complete DevOps culture. It is an extensible automation platform whose value depends on appropriate pipeline design, secure administration, reliable infrastructure, and disciplined operational practices. A poorly administered Jenkins installation can become a security risk, a bottleneck, or a single point of failure. A well-administered installation can provide repeatable, visible, and auditable delivery processes.

This chapter focuses on Jenkins administration rather than pipeline syntax alone. It explains controllers, agents, nodes, executors, plugins, credentials, permissions, webhooks, distributed builds, and maintenance. The discussion uses current Jenkins terminology: the central coordinating service is called the controller, although older documentation may use the term “master.”

Learning Objectives

By the end of this chapter, students should be able to:

  1. Explain the architecture and responsibilities of Jenkins controllers, nodes, and agents.
  2. Configure executors and allocate builds safely across distributed infrastructure.
  3. Install, evaluate, update, and govern Jenkins plugins.
  4. Store and use credentials without exposing secrets in logs or source code.
  5. Configure authentication, authorization, roles, and least-privilege access.
  6. Explain webhook-driven job execution and diagnose common integration failures.
  7. Design a basic distributed Jenkins environment and identify its operational risks.
  8. Apply maintenance, backup, monitoring, and security practices to Jenkins administration.

1. Jenkins Architecture and Core Terminology

A Jenkins installation consists of a controller, one or more nodes, jobs or pipelines, plugins, configuration data, and external integrations.

1.1 Controller

The controller is the central Jenkins service. It provides the web interface, stores global configuration, schedules work, manages plugins, records build metadata, and coordinates execution. It may execute builds itself, but using the controller as a general-purpose build machine is discouraged in production because builds can consume CPU, memory, disk, or network resources needed for administration.

The controller commonly manages:

  • job and pipeline definitions;
  • build queues and scheduling;
  • credentials and security configuration;
  • plugin lifecycle;
  • build history and test reports;
  • node and agent connectivity;
  • global tools and shared libraries; and
  • notifications and integrations.

The controller is stateful. Its important data is normally stored in the Jenkins home directory, commonly represented by the environment variable JENKINS_HOME. This directory contains job configurations, build records, plugin files, credentials configuration, user data, and cryptographic keys. Protecting and backing up this directory is therefore an administrative responsibility.

1.2 Node and agent

A node is a machine or execution environment that Jenkins can use. The controller is itself a node, while a remote node is usually called an agent. The agent process connects to the controller and executes work assigned by it.

An agent may be:

  • a physical server;
  • a virtual machine;
  • a container or pod created temporarily by a cloud integration;
  • a workstation used for a specialist build; or
  • a managed cloud instance.

Agents should be designed around the requirements of the workloads they execute. For example, a mobile application may require macOS and Xcode, whereas a Java build may require a Linux image with a particular JDK. Labels allow administrators and pipeline authors to express these requirements.

A node can have a label such as linux, docker, or mobile. A pipeline requesting a label is eligible to run only where that label is available. Labels should describe stable capabilities rather than temporary personal ownership.

1.3 Executors

An executor is a logical execution slot on a node. If an agent has four executors, it can normally run up to four concurrent tasks, subject to queueing, resource limits, and pipeline behavior. Increasing executors does not automatically increase performance. If four builds compete for two CPU cores or limited memory, they may all run more slowly and may interfere with one another.

Executor capacity should be matched to the workload. CPU-intensive compilation, memory-intensive tests, and I/O-intensive packaging have different resource profiles. A useful operational principle is to measure resource utilization rather than selecting a large executor count by assumption.

Executors are not equivalent to CPU cores. They are Jenkins scheduling slots. Their safe number depends on CPU, memory, storage, network capacity, tool behavior, container limits, and workload isolation.

1.4 Jobs, builds, and pipelines

A job is a configured unit of Jenkins automation. A build is one execution of a job. A pipeline is an automation model describing stages such as checkout, compilation, testing, packaging, security scanning, and deployment.

Jenkins supports several job styles, including freestyle projects, Pipeline jobs, multibranch Pipeline jobs, and organization-folder structures. Pipeline definitions are preferably stored as code in a Jenkinsfile, allowing them to be reviewed, versioned, and changed with the application source.

1.5 Queue and workspace

When a trigger requests execution, Jenkins places the task in a queue until an eligible executor becomes available. Scheduling considers labels, node availability, concurrency restrictions, and other policies.

A workspace is a directory in which a build checks out source code and performs operations. Workspaces must not be assumed to be permanent or clean. Builds should explicitly remove stale files, use reproducible dependency management, and avoid storing irreplaceable data only in a workspace. On shared agents, workspace isolation is important because one build must not read or modify another build’s files.

2. Controller and Agent Design

2.1 Why distributed builds are used

Distributed builds separate coordination from execution. The controller schedules and records work, while agents provide specialized or scalable execution capacity. This design offers several benefits:

  • workloads can use different operating systems and toolchains;
  • agents can scale independently of the controller;
  • resource-intensive builds are isolated from controller services;
  • ephemeral agents can reduce configuration drift; and
  • teams can allocate capacity according to workload requirements.

Distributed execution also introduces network dependencies, agent lifecycle management, platform compatibility issues, and additional security boundaries.

2.2 Connecting agents

Jenkins agents may connect using mechanisms such as inbound connections or SSH, depending on the environment and supported configuration. The connection method must be secured with encryption and authenticated identity. Administrative decisions include:

  • how the agent is provisioned;
  • which account runs the agent;
  • which tools are installed;
  • how the agent receives updates;
  • what network access it has; and
  • how it is removed or replaced.

Agents should normally run with a dedicated operating-system account and minimum required privileges. Running builds as root or an equivalent unrestricted account increases the impact of compromised dependencies or malicious build steps.

2.3 Static and ephemeral agents

A static agent remains available for repeated use. It is simple to understand but may accumulate software changes, temporary files, and configuration drift. An ephemeral agent is created for a task or short period and then destroyed. Ephemeral agents improve cleanliness and elasticity but require reliable provisioning, image management, startup time, and network integration.

Containerized agents are useful for reproducible Linux workloads, but containers do not automatically provide complete security isolation. A build that can access the container runtime socket, host filesystem, or powerful cloud credentials may affect systems outside the container.

2.4 Labels, capabilities, and workload placement

A label should communicate an execution requirement. Examples include linux-jdk17, windows, or gpu. Pipelines should request the narrowest capability that is genuinely necessary. Overly broad labels can place work on incompatible agents; overly narrow labels can create unnecessary queueing.

A sound placement policy considers:

  1. operating-system and architecture requirements;
  2. required tool versions;
  3. trust level of source code and dependencies;
  4. network and data-access needs;
  5. expected resource consumption; and
  6. concurrency and licensing constraints.

2.5 Distributed-build failure modes

Common failures include an agent going offline, incompatible tool versions, insufficient disk space, clock differences, network interruption, corrupted workspaces, and an agent lacking permission to access a required service. Diagnosis should begin with the queue, node status, agent log, workspace state, resource metrics, and the relevant build console output.

3. Jenkins Plugins and Extensibility

Plugins provide much of Jenkins’ functionality. They support source-control systems, pipeline steps, authentication, cloud agents, test reporting, artifact management, notifications, and user interfaces. This extensibility is a major strength, but it creates a substantial governance responsibility.

3.1 Plugin dependencies

A plugin may depend on other plugins and on a particular Jenkins core version. Installing or upgrading one plugin can therefore change a larger dependency graph. Administrators should review dependency information, compatibility warnings, security advisories, release notes, and test results before applying changes to a production controller.

A plugin should be selected because it has a clear business or technical purpose, not merely because it offers a convenient shortcut. Each additional plugin increases the maintenance surface and potentially the attack surface.

3.2 Plugin administration practices

Recommended practices include:

  • maintain a documented inventory of installed plugins;
  • remove unused plugins;
  • test upgrades in a non-production environment;
  • update Jenkins core and plugins through a controlled process;
  • monitor security advisories;
  • restrict plugin installation to trusted administrators; and
  • retain a rollback or recovery plan.

Plugin files and configuration should be included in backup and disaster-recovery planning. However, a backup is not proven until restoration has been tested.

3.3 Configuration as code

Jenkins configuration can be managed manually through the web interface, but significant installations benefit from configuration as code. Pipeline definitions should normally be held in source control. Global settings may be managed through the Jenkins Configuration as Code (JCasC) approach where appropriate. This improves reviewability and repeatability, although secrets must still be handled through secure secret-management mechanisms rather than committed as plain text.

4. Credentials and Secret Management

Jenkins frequently needs credentials for source repositories, artifact repositories, cloud platforms, container registries, signing systems, and deployment targets. Credentials are sensitive assets, not ordinary configuration values.

4.1 Credential types and scope

Common credential forms include username and password, secret text, SSH private keys, certificates, and cloud-provider identities. Credentials may be scoped globally or to a folder, depending on organizational design. Narrow scope reduces accidental use and limits exposure.

A credential identifier, or credential ID, allows a pipeline to request a secret without embedding the secret value in the Jenkinsfile. For example, a pipeline can use a credentials binding to make a secret available temporarily to a command. The secret should not be printed, placed in an artifact, or written into a source-controlled file.

4.2 Secure use of credentials

Good practice includes:

  • use short-lived or dynamically issued credentials where possible;
  • grant only the permissions required by the task;
  • rotate credentials on a defined schedule and after suspected compromise;
  • avoid passing secrets as command-line arguments when process listings may expose them;
  • prevent secrets from appearing in console logs;
  • restrict who can configure jobs that access sensitive credentials; and
  • audit credential use.

Masking is useful but not infallible. A secret can be exposed through shell tracing, transformed output, diagnostic archives, error messages, or malicious build code. Anyone able to alter a trusted pipeline or run arbitrary code on a trusted agent may be able to access credentials available to that build.

4.3 Secret boundaries

A critical distinction is between a Jenkins administrator, a pipeline author, and a build process. Granting job configuration rights to an untrusted user may effectively grant access to any credential usable by that job. Permission design must therefore consider indirect access, not only whether the user can view a credential in the interface.

5. Authentication, Authorization, and Permissions

Authentication answers “Who is the user?” Authorization answers “What may that user do?” Jenkins can integrate with local users, LDAP, Active Directory, single sign-on, and other identity systems through supported mechanisms.

5.1 Authorization strategies

Jenkins authorization options may include logged-in users having broad permissions, matrix-based permissions, project or folder-based permissions, role-based permissions through appropriate plugins, and external identity integration. The precise available strategy depends on the Jenkins version and installed plugins.

Least privilege is the central principle: grant the minimum permissions needed for a defined responsibility. Typical roles may include:

  • platform administrator;
  • pipeline or project maintainer;
  • build operator;
  • read-only auditor; and
  • service account.

Permissions should be assigned to groups rather than individual users whenever possible. Service accounts should have identifiable ownership, documented purpose, limited scope, and periodic review.

5.2 High-risk permissions

Permissions such as overall administration, script execution, job configuration, credential management, and agent management require special care. Script execution can be extremely powerful because Jenkins scripts may access internal APIs and the host environment. It should not be treated as an ordinary troubleshooting privilege.

5.3 Governance and auditability

A professional Jenkins service should document who can install plugins, change security settings, approve scripts, create credentials, configure webhooks, and modify deployment jobs. Changes should be reviewed and recorded. Central identity management, multi-factor authentication where available, audit logs, and periodic access reviews strengthen governance.

6. Webhooks and Event-Driven Automation

A webhook is an HTTP request sent by a source-control or external system when an event occurs, such as a commit, pull request, tag, or repository change. Webhooks allow Jenkins to respond promptly without repeatedly polling a repository.

A typical flow is:

  1. A developer pushes a commit to the repository.
  2. The source-control platform sends an authenticated webhook request.
  3. Jenkins receives and validates the request.
  4. Jenkins identifies the relevant job or multibranch project.
  5. The job evaluates whether the event should trigger a build.
  6. Jenkins places the build in the queue.
  7. An eligible agent executes the pipeline.
  8. Jenkins reports status back to the source-control platform.

Webhook configuration requires an accessible endpoint, correct event selection, authentication or signature validation, and suitable network controls. The endpoint should not be exposed more broadly than necessary. Reverse proxies, firewalls, TLS certificates, and IP restrictions may be part of the design.

Webhook troubleshooting should examine delivery history at the source system, HTTP response codes, Jenkins logs, job trigger configuration, branch discovery, multibranch indexing, and duplicate-event behavior. A successful HTTP delivery does not guarantee that a build was scheduled; the payload may be valid but irrelevant to the configured job.

7. Scheduling, Concurrency, and Distributed Builds

Jenkins scheduling balances demand against available executors and constraints. A build may remain queued because no node matches its label, all matching executors are busy, a concurrency restriction is active, or an external resource is unavailable.

Useful controls include:

  • labels for capability-based placement;
  • disabling concurrent builds where shared environments cannot support them;
  • throttling categories for scarce resources;
  • quiet periods to combine rapid successive changes where appropriate;
  • milestone or lock mechanisms for ordered or exclusive operations; and
  • separate agents for trusted and untrusted workloads.

The number of executors is an operational capacity decision. If the average arrival rate of work approaches or exceeds sustainable service capacity, queue times increase. In simple terms, a system is unstable when demand persistently exceeds capacity. Real Jenkins systems are more complex because jobs have varying durations and resource requirements, so administrators should use queue-time metrics, executor utilization, build duration, failure rates, and host-level resource data rather than relying on a single capacity number.

Build isolation is especially important for pull requests from forks or other untrusted contributors. Such builds may execute attacker-controlled code. They should not automatically receive production credentials, unrestricted network access, or privileged agent capabilities.

8. Operational Administration and Maintenance

8.1 Backup and recovery

A Jenkins backup strategy should cover Jenkins home, job definitions, credentials configuration, plugin information, security settings, and any external systems required to reconstruct operation. Build artifacts may be stored externally rather than retained indefinitely on the controller.

Backups should be encrypted, access-controlled, versioned, and tested through restoration exercises. A backup that cannot be restored within the required time is not an adequate recovery solution. Administrators should define recovery objectives, including the maximum acceptable data loss and restoration time, in cooperation with the organization.

8.2 Monitoring

Monitoring should include:

  • controller CPU, memory, storage, and file-descriptor usage;
  • executor utilization and queue wait time;
  • agent online and offline status;
  • build duration and failure rate;
  • webhook delivery failures;
  • plugin and security warnings;
  • log volume and disk growth; and
  • backup success and restoration readiness.

Build failure is not always a Jenkins failure. A useful classification distinguishes source or test failure, infrastructure failure, configuration failure, dependency failure, and security-policy failure. This classification improves incident response and reporting.

8.3 Upgrade management

Jenkins upgrades should be planned. Administrators should review compatibility, back up the installation, test representative pipelines, communicate maintenance windows, and define rollback or rebuild procedures. Long periods without updates increase exposure to known vulnerabilities and make eventual upgrades more difficult.

8.4 Housekeeping

Build retention policies should remove obsolete records according to operational and compliance needs. Logs and artifacts can consume large amounts of storage. Workspace cleanup, artifact archiving, external artifact repositories, and retention rules help control growth. Retention must not remove evidence required for audits, incident analysis, or regulatory obligations.

9. Applied Case: A Distributed Jenkins Service for a Retail Application

The following is an illustrative case.

Background

A retail organization operates a Java web application and an Android mobile application. Its single Jenkins controller also performs builds. Developers report slow web access, long queues, inconsistent tool versions, and occasional failures caused by full disk space.

Problem analysis

Investigation shows that the controller runs four concurrent builds despite having limited memory. Android builds require a large SDK and consume substantial storage. Webhook requests are sometimes rejected by a reverse proxy. Deployment credentials are available to more jobs than necessary, and plugins have been installed without a documented review process.

Approach and solution

The organization adopts the following design:

  1. The controller is reserved primarily for coordination and administration.
  2. A Linux agent is created for Java builds, with a documented JDK and build-tool image.
  3. A dedicated Android agent is provisioned with controlled SDK versions and sufficient storage.
  4. Labels such as java-linux and android are applied according to capabilities.
  5. Executor counts are set after observing CPU, memory, and build-duration data.
  6. Deployment credentials are moved to a restricted folder scope and are available only to approved deployment jobs.
  7. Pull-request builds from external contributors run on isolated agents without production credentials.
  8. Repository webhooks are configured through TLS and validated using the source platform’s supported authentication mechanism.
  9. Plugin inventory, upgrade testing, backups, and monitoring are added to the operating procedure.
  10. Build artifacts are stored in an artifact repository rather than retained indefinitely on the controller.

Outcome

Controller responsiveness improves because compilation and Android packaging are moved to agents. Queue time falls for ordinary Java builds, while Android work receives predictable capacity. The organization also gains clearer audit records and a smaller credential exposure boundary. Some complexity increases: agent images must be maintained, and the network path between controller and agents must be monitored.

Learning points

The case demonstrates that Jenkins administration is a systems problem rather than a collection of interface settings. Performance, security, reliability, and maintainability are connected. Distributed execution solves some bottlenecks but introduces lifecycle and governance requirements. Capacity decisions should be evidence-based, and security boundaries must follow the trust level of the code being executed.

10. Challenges, Limitations, and Contemporary Practice

Jenkins is highly flexible, but flexibility can produce inconsistent configuration, plugin sprawl, difficult upgrades, and fragmented ownership. A large installation may require folder structures, shared libraries, configuration as code, standardized agent images, and platform engineering practices.

Jenkins also requires careful treatment of software supply-chain risk. Pipelines download dependencies, invoke plugins, use container images, and may publish artifacts. Organizations should verify dependencies where practical, restrict outbound access when appropriate, scan artifacts, protect signing keys, and record provenance. Automated security tools support these goals but do not replace human review.

AI-assisted coding and automated agents can increase build volume and may generate code or configuration that Jenkins executes. This makes validation, sandboxing, approval controls, and credential isolation more important. AI output should not be trusted merely because it is syntactically valid. Build policies should treat generated code as code supplied by a potentially untrusted source until reviewed and tested.

A contemporary Jenkins service therefore combines:

  • pipeline definitions in source control;
  • reproducible and replaceable agents;
  • secure identity and secret management;
  • controlled plugin governance;
  • observable queues and builds;
  • tested backups and recovery procedures; and
  • explicit separation between trusted deployment processes and untrusted verification workloads.

Chapter Summary

Jenkins is an extensible automation server whose controller schedules work, manages configuration, stores build information, and coordinates agents. Nodes provide execution environments, while executors define logical concurrent work slots. Effective distributed-build design uses labels, capability-based placement, suitable agent isolation, and measured capacity rather than simply increasing executor counts.

Plugins extend Jenkins but require inventory, compatibility testing, security monitoring, and removal of unnecessary components. Credentials must be scoped, rotated, protected from logs, and made available only to trusted jobs. Authentication identifies users; authorization determines their permissions, and least privilege should guide both human and service-account access.

Webhooks provide event-driven execution but require secure endpoints, correct job discovery, and systematic troubleshooting. Operational administration includes monitoring, storage and workspace housekeeping, upgrade planning, tested backups, recovery procedures, and access reviews. The central professional principle is that Jenkins is production infrastructure: it must be designed, secured, observed, and maintained accordingly.

Key Terms

Controller: The central Jenkins service that schedules work and manages configuration.

Agent: A remote execution environment connected to a Jenkins controller.

Node: A machine or execution environment available to Jenkins; the controller is also a node.

Executor: A logical slot that permits a node to run a task.

Job: A configured unit of Jenkins automation.

Build: One execution of a job.

Pipeline: A defined sequence or graph of automated delivery activities.

Workspace: A directory used by a build to check out and process source code.

Label: A capability identifier used to select suitable nodes.

Plugin: An extension that adds functionality to Jenkins.

Credential: A secret or authenticated identity used to access another system.

Credential ID: A reference used by a job to request a stored credential without embedding its value.

Authentication: The process of establishing a user’s identity.

Authorization: The process of determining what an authenticated identity may do.

Webhook: An HTTP event notification sent by an external system to Jenkins.

Queue: The set of tasks waiting for an eligible executor.

Ephemeral agent: A temporary agent created for limited use and then removed.

Least privilege: Granting only the access required for a defined task.

Configuration as code: Managing system configuration through versioned, repeatable declarations.

Supply-chain security: Protection of source code, dependencies, tools, artifacts, and delivery processes.

Review Questions

Short Answer Questions

  1. What are the principal responsibilities of a Jenkins controller?
  2. Define an executor and explain why executor count is not the same as CPU-core count.
  3. What is the purpose of a Jenkins label?
  4. Why should credentials be referenced by credential ID rather than placed directly in a Jenkinsfile?
  5. What information should be examined when a webhook is delivered but no build starts?

Long Answer Questions

  1. Explain the architecture of a Jenkins controller-agent system and discuss the advantages and risks of distributed builds.
  2. Describe a secure process for selecting, installing, updating, and removing Jenkins plugins.
  3. Compare static and ephemeral agents with respect to reproducibility, maintenance, scalability, and security.
  4. Explain how authentication, authorization, roles, service accounts, and least privilege should be combined in Jenkins administration.
  5. Design a backup, monitoring, and upgrade policy for a medium-sized Jenkins installation.

Analytical / Application Questions

  1. A controller has eight executors, but its host has four CPU cores and limited memory. Builds are slow and the web interface is unresponsive. Analyze the likely causes and propose an evidence-based redesign.
  2. A pull-request job from an external repository needs to run tests but currently has access to a cloud deployment credential. Identify the security risks and design safer agent, credential, and approval controls.
  3. A team experiences long queues even though several agents appear online. Develop a diagnostic sequence covering labels, executor availability, resource utilization, concurrency restrictions, webhooks, and workspace or tool failures.

Multiple Choice Questions with Answers

Question 1

Which component primarily schedules Jenkins work and manages global configuration?

A. The controller

B. The workspace

C. The source repository

D. The artifact repository

Correct Answer: A. The controller

Question 2

What does a Jenkins executor represent?

A. A physical CPU core

B. A logical slot for running a task

C. A stored user credential

D. A source-control branch

Correct Answer: B. A logical slot for running a task

Question 3

Why are labels applied to Jenkins nodes?

A. To encrypt build logs

B. To identify users who created builds

C. To select nodes with required capabilities

D. To determine credential passwords

Correct Answer: C. To select nodes with required capabilities

Question 4

Which practice best protects a Jenkins credential?

A. Commit the secret to the Jenkinsfile

B. Print the secret for troubleshooting

C. Use a scoped credential reference and restrict job access

D. Place the secret in a public artifact

Correct Answer: C. Use a scoped credential reference and restrict job access

Question 5

What is the main purpose of a webhook in a CI workflow?

A. To notify Jenkins of an external event

B. To increase the number of executors

C. To replace all Jenkins plugins

D. To archive every workspace permanently

Correct Answer: A. To notify Jenkins of an external event

Question 6

Which statement about plugins is most accurate?

A. Unused plugins should remain installed for convenience

B. Plugins can have dependencies and security implications

C. Plugins never affect Jenkins core compatibility

D. Plugin updates do not require testing

Correct Answer: B. Plugins can have dependencies and security implications

Question 7

Which principle should guide Jenkins permission design?

A. Maximum privilege for all developers

B. Least privilege for defined responsibilities

C. Anonymous administration

D. Shared personal accounts

Correct Answer: B. Least privilege for defined responsibilities

Question 8

Why are ephemeral agents often useful?

A. They eliminate the need for network connectivity

B. They reduce configuration drift by being recreated

C. They allow all builds to access production credentials

D. They permanently store every workspace

Correct Answer: B. They reduce configuration drift by being recreated

Question 9

A build remains queued although an agent is online. Which is a plausible cause?

A. No available executor matches the job’s label

B. The controller has no web interface

C. The source code has been compiled successfully

D. The job has too many archived artifacts

Correct Answer: A. No available executor matches the job’s label

Question 10

Which backup practice provides the strongest operational assurance?

A. Assume that copied files are recoverable

B. Back up only the current console log

C. Test restoration and protect backup access

D. Store an unencrypted backup beside the controller

Correct Answer: C. Test restoration and protect backup access

CI/CD Pipelines with Jenkins or GitHub Actions
Chapter 4 of 14