Chapter 07Lesson 03~90 minutes

Build Parameters, Environment Variables, Build Causes, Schedules, Remote Triggers, and Parameterized Automation: Configuration, Design Choices, and Tradeoffs

Choose parameter, environment, trigger, authentication, validation, and rerun patterns according to ownership, trust, auditability, failure isolation, and the side effects the job can create.

Design tradeoffsLeast privilegeCron vs eventsAPI identityAllowlistsRerun semantics

Learning objectives

  • Choose parameters versus environment variables based on ownership and lifecycle rather than convenience.
  • Compare timers with event/webhook triggers and understand their capacity and failure characteristics.
  • Prefer attributable API-token identities over anonymous/URL-token trigger patterns.
  • Use allowlisted control inputs for operational targets instead of free-form production selectors.
  • Decide when a rerun is safe, when an immutable new input is required, and when manual reconciliation is necessary.

1. Design inputs around ownership, not syntax

A Jenkins parameter and an environment variable can both appear to a shell as text, yet they have different ownership. A parameter is part of the job's public invocation contract. An environment variable can originate from controller configuration, the agent OS, a parameter export, Pipeline configuration, a plugin, or a credential binding. Treating them as interchangeable hides who is allowed to set the value.

Before choosing an input mechanism, ask: Who owns this value? Who may change it? Is the value secret? Does it select an external target? Must it be reviewable in SCM? Can a timer supply a safe default? What happens if the same request runs twice?

2. Parameter versus environment variable

Need Prefer Why
Human/API chooses a bounded behavior per run Parameter Visible invocation contract and build-level evidence.
Stable non-secret controller/agent configuration Managed environment/global property Not repeated as user input on every build.
Stage-local Pipeline setting Stage environment Narrower scope than a global variable.
Secret Credentials binding / external secret provider Parameters and ordinary environment configuration are not secret-management boundaries.
External release identity Immutable parameter such as artifact digest/version Allows the build record to prove exactly what was requested.

Avoid designs where users can indirectly choose sensitive environment variable names. Jenkins security guidance specifically calls out variables such as PATH and platform loader variables because they can change which programs execute.

3. Timer versus webhook/event trigger

A timer asks “should this job run now?” regardless of whether the underlying source or target changed. A webhook/event trigger asks “did a relevant event occur?” Event-driven triggering usually reduces unnecessary work and feedback latency, but it introduces provider/webhook delivery and authentication dependencies. A timer is simpler and can be useful for housekeeping, reconciliation, or scheduled maintenance.

Criterion Timer Webhook/event
Trigger precision Time-based Change/event-based
Load behavior Can create periodic spikes; prefer H Bursty with event rate
External dependency Clock/controller scheduler Provider delivery, endpoint, authentication
Missed-event recovery Next schedule may reconcile Often needs retry/reconciliation strategy
Good fit Nightly verification, cleanup, reconciliation Fast CI feedback, repository/provider events

4. Remote build token versus API-token identity versus human action

A human UI build has a human session and user identity. An authenticated Remote API call should use a dedicated least-privilege service identity and API token. Legacy job-level remote trigger tokens can be convenient, but putting a token in a URL increases leakage risk and often provides weaker attribution. Prefer authentication that Jenkins can tie to a principal with explicit permissions.

Do not solve a scripted-client error by disabling CSRF. Current Jenkins behavior exempts API-token-authenticated requests from the crumb requirement; password-authenticated clients generally need crumb/session handling.

5. Free-form input versus allowlisted choice

If a parameter decides an operational target, a short allowlist is easier to reason about than arbitrary text. A choice like dev/staging prevents many typos and narrows the threat surface. Still validate the value in the execution layer.

Free-form strings remain appropriate for bounded data such as a ticket ID or immutable package version, but validate structure and length. A version string that later becomes part of a filesystem path or URL should be encoded/validated for that context.

6. Rerun versus immutable new input

Rerunning is reasonable when the operation is idempotent and the intended target identity has not changed. If a build is meant to publish or deploy an immutable artifact, prefer passing the immutable artifact ID/digest again rather than rebuilding from a mutable branch. If the original attempt partially changed an external system, reconcile target state before rerunning.

Replay is not rollback. Pipeline Replay changes script execution for a run. It does not revert external side effects from a previous build. A Freestyle “Build with Parameters” creates a new build record; it does not recreate the previous external world.

7. Scheduling, concurrency, and idempotency are one design problem

A schedule interval shorter than worst-case runtime can create queue growth or overlapping external operations. The correct response is not automatically “more executors.” First decide whether overlaps are valid. If not, serialize the job or external resource, make the operation idempotent, and choose a schedule that reflects actual duration and capacity.

Use H to distribute start times, but understand its role: it spreads load; it does not prevent two builds of the same job from overlapping when concurrency is enabled.

8. Worked decision: a nightly cache rotation

Decision Selected pattern Reason / evidence
Target Choice parameter dev|staging + execution allowlist No production target exists in the job contract.
Timing H H * * * Daily but load-distributed; exact minute is unimportant.
Manual override UI or authenticated API user Attributable principal and build cause.
Secret None in lab; Credentials later for real integrations No secret enters parameter history.
Idempotency Marker/current-state check before mutation Rerun becomes no-op when target is already correct.
Evidence Build cause + params + target marker/state Separates Jenkins success from external outcome.

9. Pipeline preview: the same contract becomes code later

Later Pipeline chapters will formalize these concepts in a Jenkinsfile. The important preview is ownership: Declarative parameters defines the build invocation contract, environment defines scoped runtime variables, and triggers defines automated causes. Do not rush into syntax before you can state the trust boundary.

pipeline {
  agent { label 'lab-linux' }
  parameters {
    choice(name: 'TARGET', choices: ['dev', 'staging'])
    booleanParam(name: 'DRY_RUN', defaultValue: true)
  }
  triggers { cron('H H * * *') }
  stages {
    stage('Validate') {
      steps {
        echo "target=${params.TARGET}, dryRun=${params.DRY_RUN}"
      }
    }
  }
}

This is only a preview. Chapter 09–10 will teach Pipeline execution and Declarative syntax in depth.

10. Production decision checklist

  • Can the input select a privileged target or operation?
  • Is the input value visible in build history or logs?
  • Does a least-privilege principal own the API call?
  • Is the schedule hashed and capacity-aware?
  • Is concurrency intentional?
  • Will a second identical request be safe?
  • Can you prove the actual cause, build identity, and external target state?
Next lesson

Diagnostics, Failure Modes, Security, and Performance

Diagnose injection, target-selection mistakes, token leakage, overlapping timers, and unsafe reruns without erasing first-failure evidence.

Knowledge check

A deployment target changes per build. Parameter or global environment variable?

Why is an API token preferable to a token placed in the URL?

Does H prevent overlapping builds?

When is a rerun unsafe even with identical Jenkins parameters?

Why keep secrets out of ordinary build parameters?

Official references and version notes

Version and compatibility note

Rechecked on 2026-09-16. Examples target Jenkins 2.568.3 LTS, which is tested with Java 21 and 25; the disposable lab uses Java 21. The chapter intentionally relies on Jenkins core/Freestyle parameter, timer, build-cause, environment, and Remote API behavior so mandatory completion does not depend on a commercial service or a specialized trigger plugin. Exact cause payloads and environment variables can vary by job type and installed plugins, so inspect the controller's own .../api/ output rather than assuming a fixed payload.

Keep the academy open

Support free, practical DevOps education.

Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.

Ethereum / ERC-20
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this address.