You schedule a Jenkins build "by source code" by declaring a trigger in the job definition—most commonly triggers { cron('...') } inside a Jenkinsfile, or a triggers block in Job DSL—and then letting Jenkins load that definition; a schedule cannot be toggled from ordinary build source files alone, because Jenkins only acts on trigger configuration that exists in a job it has already created.
What "schedule in Jenkins by source code" can mean
The phrase bundles two different things, and the answer depends on which you mean:
1: Declarative or scripted Pipeline stored in a Jenkinsfile in your repository, including a triggers block that Jenkins reads when the job is defined "from SCM." 2: Job configuration as code via the Job DSL plugin, JCasC (Configuration as Code), or a seed job that creates/updates jobs, where the schedule lives in a Groovy or YAML definition rather than in the Pipeline script.
A third, weaker reading is "schedule a build from my application code using the Jenkins remote API"—that is triggering, not scheduling, and it is not persistence-friendly. The first two are the durable, reproducible answers; the third is worth distinguishing because it's a frequent source of confusion.
There is also an ambiguity about where the schedule runs. Pipeline cron triggers are evaluated by the Jenkins controller from the job's stored configuration. If you edit the Jenkinsfile in your repo but the job is not configured to re-read that file (for example, a Multibranch Pipeline rescans on a timer or webhook), the new schedule will not take effect until Jenkins processes the updated definition. That gap between "code committed" and "schedule active" is the single biggest practical pitfall.
Declarative Pipeline: triggers { cron(...) }
In a Declarative Pipeline, the triggers directive goes at the top level of the pipeline block, alongside agent, stages, and post:
The string is a standard five-field cron expression (minute, hour, day-of-month, month, day-of-week), evaluated in the Jenkins controller's time zone unless configured otherwise. The H symbol is Jenkins' hash token: instead of a fixed minute, Jenkins spreads jobs across the interval to avoid a thundering herd of simultaneous builds. H 2 * * 1-5 means "sometime in the 2 a.m. hour, Monday through Friday," with the exact minute derived from a hash of the job name. That hash is stable for a given job name, so it doesn't wander between runs, but it also means two identically named jobs in different folders may land on different minutes if the hash input differs.
A few concrete distinctions matter here:
H/15 * * * * runs every 15 minutes, offset by the job's hash, not exactly at :00/:15/:30/:45. 0 2 * * * is a fixed 2:00 a.m. run; all such jobs fire together. @daily, @midnight, @weekly, @monthly are supported aliases in Jenkins cron syntax. H H(0-3) * * * lets Jenkins pick both a hash-stable hour within 0–3 and a minute, useful when you want "sometime overnight" without pinning a moment.
Do not confuse this cron with a Unix crontab entry you install on a build agent. Pipeline cron triggers are a Jenkins feature; an agent-side crontab that calls the Jenkins CLI or HTTP API is a different mechanism with different failure modes (the agent must be up, credentials must be present, and the trigger is invisible to Jenkins' schedule view).
Scripted Pipeline equivalent
In scripted Pipeline, the trigger is a property on the job:
The properties(...) call must execute during the run for the trigger to be applied—so the first run after adding it establishes the schedule, and a later run that skips the block (for example, behind a conditional) can leave the previous trigger in place. This asymmetry between "declared" and "applied" is a real source of surprises in scripted jobs.
Job DSL: schedule as generated configuration
If you manage jobs from a seed job, the schedule is part of the DSL:
Running the seed job regenerates or updates example/nightly-build with that trigger. The advantage is that the schedule is versioned and reviewable alongside the job's other settings—SCM, steps, notifications. The hazard is that the seed job's DSL is the source of truth: manual edits in the Jenkins UI to that job will be overwritten on the next seed run, and a schedule added only via the UI (not in the DSL) will be lost. If you're using the jobDsl step with the removedJobAction/removedViewAction options, understand what those do before relying on them, because they govern cleanup of jobs no longer described in the DSL.
JCasC (Configuration as Code) is a related but distinct route: it can define jobs too, and is often paired with the Job DSL plugin. JCasC is aimed at controller-wide configuration (credentials, security, clouds), while per-job schedules are usually cleaner in Job DSL or in the Jenkinsfile. Mixing the two without a clear ownership boundary is a common way to get schedule drift.
Multibranch and Organization folders
For Multibranch Pipeline projects, the triggers block in the branch's Jenkinsfile applies to each branch job that Jenkins indexes. The job has to discover the branch and read the file first. Two consequences:
New branches don't get a schedule until they're indexed. Depending on your scan configuration (periodic folder scan, webhook, or both), there's a lag. The H hash differs across branches if the job's full name differs, so sibling branch jobs may not run at the same minute. If you need synchronized timing across branches, use a fixed minute and accept the burst, or use parameterizedCron (below).
Organization folders behave the same way at the repository level: the schedule is read from each repo's Jenkinsfile, not set centrally in the folder.
Parameterized schedules
The parameterizedCron plugin lets one job have different cron entries that pass different parameters on each firing:
This is useful when a nightly and a weekly job share a pipeline. It requires the plugin to be installed; plain cron cannot pass parameters. Note the % separator and the ; between parameters—getting the delimiters wrong is a routine error, and the plugin's behavior with malformed lines is not always obvious (a bad line may be ignored rather than fail the build).
The trigger types you're probably comparing
"Cron" is one of several triggers; knowing the alternatives prevents choosing the wrong tool:
cron / parameterizedCron: time-based, controller-evaluated. pollSCM: periodically checks the SCM for changes and builds if the revision moved. This is polling, not scheduling a build at a fixed time, and it's increasingly discouraged in favor of webhooks. upstream: builds after another job finishes, with optional result filters. Webhook-driven (GitHub, GitLab, Bitbucket): builds on push/PR events; not time-based, but the modern default for CI. githubPush() and similar SCM-specific triggers: installed by plugins, not core cron.
If your actual goal is "build whenever code changes," cron is the wrong instrument; use a webhook or Multibranch with SCM discovery. Cron is for periodic work: nightly integration tests, dependency refresh, reports, cleanup.
Why a Jenkinsfile cron may not take effect
This is where most "I scheduled it but it doesn't run" reports originate. The schedule you write is only honored if Jenkins has stored it on the job. Check, in order:
1: Is the job reading the Jenkinsfile from SCM? A Pipeline job configured with an inline script will not pick up a triggers block in a repository file. The job's "Definition" must be "Pipeline script from SCM," and the branch/path must point at the file you edited. 2: Has the job run or been rescanned since the edit? For Multibranch, a branch index/scan is required. For a plain Pipeline-from-SCM job, the trigger configuration is generally read when the job runs; a job that has never successfully run may not have applied the block. Trigger the first build manually. 3: Is the controller's clock and time zone what you expect? Cron is evaluated in the controller JVM's default time zone unless the user.timezone property or the TZ/org.apache.commons.jcs settings override it. A job set for "2 a.m." can fire at an unexpected wall-clock time across DST transitions; Jenkins does not always handle DST the way operators assume. 4: Is the controller actually scheduling? If the controller is heavily loaded or paused (quiet down / "Prepare for shutdown"), builds may not fire. Check "Manage Jenkins" for the quiet-down state. 5: Did another configuration source overwrite the job? A seed job or JCasC run can reset the trigger; UI edits can be blown away by the next DSL application. 6: Is H collapsing to an unexpected minute? The hash is deterministic but not intuitive; use "Build Triggers" → the schedule field's help, or temporarily switch to a fixed minute to verify the rest of the chain.
Also confirm the build isn't being skipped by a when condition, input step, or a quiet period. The default quiet period (often 5 seconds) delays firing; a large quiet period set globally or on the job can make a cron run appear late. And a job that fails early (missing agent, bad label) still fires—so distinguish "never triggered" from "triggered but failed" in the build history, which shows the cause ("Started by timer") when cron is responsible.
Scheduling without a Jenkinsfile: UI and API
You can schedule from the UI—configure the job, check "Build periodically," and paste a cron string. That is not source code, and it will drift from your repository. You can also create or update jobs over the Jenkins HTTP API with a config XML that includes a hudson.triggers.TimerTrigger, but that is imperative scripting against a live controller, not declarative source of truth, and it requires authentication and CSRF handling. Treat both as fallbacks for jobs you cannot yet move to Pipeline or Job DSL.
A frequent misconception is that a Jenkinsfile committed to a branch is the schedule, full stop. It isn't: it is a requested schedule that the controller applies to the job it builds for that branch. The controller's stored configuration is what the timer consults. In practice this means the git history of the schedule and the controller's actual schedule can disagree, and reconciling them means understanding step 1 and 2 above.
Practical guidance
Keep the schedule in the Jenkinsfile for Pipeline jobs and in Job DSL for large fleets; avoid hand-editing the UI for anything versioned. Prefer H over fixed minutes for shared infrastructure to spread load, and fixed minutes when you specifically need a wall-clock moment (deadline-driven reports, timezone-bound upstream data). Use parameterizedCron when one pipeline serves multiple cadences; don't create duplicate jobs just to vary the time. Verify the trigger end-to-end by checking a build's "Started by timer" cause, not just by reading your code. Remember that cron triggers are controller-evaluated: agents being offline does not stop the trigger, but it will stop the build from executing, which can look like a scheduling failure from the outside.
If you tell me whether you're using a plain Pipeline job, a Multibranch project, or Job DSL, and whether the job is "Pipeline script from SCM," I can point to the exact place your schedule should live and the exact step that applies it.