Automation

Azure Automation: diagnose job schedule drift before changing the runbook

A production runbook for reconciling Azure Automation schedules, jobSchedule associations, parameters, Hybrid Worker targets and job evidence before repairing or rolling back a scheduled execution.

11 Nov 2026 azureazure-automationschedulesjob-schedulerunbookparametershybrid-workerdriftobservabilityautomationcanaryrollbackproduction

A scheduled Azure Automation job runs the right published runbook with the wrong scope. A manual start against a test resource succeeds, so the team prepares to edit the code. The defect is elsewhere: the schedule-to-runbook association still carries an old subscription parameter and targets a Hybrid Worker group that was retired during a migration.

This is a common diagnostic trap. Azure Automation separates the schedule, the jobSchedule association, the published runbook and each resulting job. A runbook can be linked to several schedules, and one shared schedule can start several runbooks. The effective parameters and runOn target belong to the association, not to the schedule alone.

The running case is a nightly maintenance runbook that must operate on production resources. The goal is to decide whether to keep the association, recreate it with a corrected contract, suspend the next execution or restore the last known configuration without changing working runbook code.

Freeze the next execution and preserve the contract

First determine when the next run can start and how broadly the schedule is shared. If the next execution is close, contain it before investigating. Disabling a shared schedule also stops every other linked runbook, so do not use that action until the associations are inventoried. When only one association is faulty, remove or replace that association through the normal change path instead of silencing unrelated automation.

yaml 01-scheduled-runbook-incident.yml
incident: INC-AUTO-1137
automation_account: aa-operations-prod
runbook: Invoke-NightlyMaintenance
reported_symptom: job targeted the wrong subscription
next_schedule_utc: 2026-11-12T01:00:00Z

freeze:
- schedule definition and enabled state
- every jobSchedule linked to the schedule
- published runbook version or release marker
- association parameters and runOn
- last healthy and first faulty job IDs
- job status, streams and target-side audit evidence

do_not_yet:
- edit or republish the runbook
- disable a shared schedule blindly
- rerun the failed job
- recreate the association without preserving its ID and parameters

Record times in UTC. A portal screenshot is not enough: it does not provide a reviewable representation of every association and can hide parameter values behind separate panes.

Separate four Azure Automation objects

Treat the execution chain as four distinct objects:

  1. The schedule defines recurrence, timezone, enabled state and next run.
  2. The jobSchedule binds one schedule to one runbook, parameters and an optional Hybrid Worker group through runOn.
  3. The published runbook is the code artifact that scheduled jobs execute.
  4. The job is one execution with its own ID, status, timestamps, parameters and streams.

A green manual job proves that the published artifact can run with the parameters supplied manually. It does not prove that the scheduled association supplies the same values or uses the same worker group. Likewise, a correct schedule time does not prove which runbooks and parameters it will start.

Build the hypothesis around the first boundary that differs between a healthy and faulty execution. Typical causes are a stale environment parameter, a renamed Hybrid Worker group, a duplicate association created by infrastructure as code, a shared schedule reused by mistake, or several staggered schedules that now overlap because the runbook duration increased.

Inventory the effective associations through ARM

Export the schedule and every jobSchedule from the Automation account. The association identifier is a UUID, so search by the runbook and schedule names rather than assuming a human-readable resource name.

bash 02-export-job-schedule-contract.sh
SUBSCRIPTION_ID="<subscription-id>"
RG="rg-automation-prod"
ACCOUNT="aa-operations-prod"
SCHEDULE="nightly-maintenance"
RUNBOOK="Invoke-NightlyMaintenance"
API_VERSION="2024-10-23"
BASE="https://management.azure.com/subscriptions/$SUBSCRIPTION_ID/resourceGroups/$RG/providers/Microsoft.Automation/automationAccounts/$ACCOUNT"

az rest \
--method get \
--url "$BASE/schedules/$SCHEDULE?api-version=$API_VERSION" \
--output json > schedule.json

az rest \
--method get \
--url "$BASE/jobSchedules?api-version=$API_VERSION" \
--output json > job-schedules.json

jq --arg schedule "$SCHEDULE" --arg runbook "$RUNBOOK" '
[.value[]
 | select(.properties.schedule.name == $schedule
       or .properties.runbook.name == $runbook)
 | {
     id,
     jobScheduleId: .properties.jobScheduleId,
     schedule: .properties.schedule.name,
     runbook: .properties.runbook.name,
     runOn: .properties.runOn,
     parameters: .properties.parameters,
     createdAt: .systemData.createdAt,
     createdBy: .systemData.createdBy,
     lastModifiedAt: .systemData.lastModifiedAt
   }]
| sort_by(.schedule, .runbook, .jobScheduleId)
' job-schedules.json > matching-associations.json

Review both directions. Filtering only on the runbook misses other runbooks attached to the shared schedule. Filtering only on the schedule misses a second schedule attached to the same runbook. Count the matching associations and compare their creation time with deployments, migrations and incident onset.

Do not store secrets as association parameters. Scheduled parameters are configuration, not a secret transport. Pass references and let the runbook retrieve protected values under its execution identity.

Compare declared and effective state

Normalize the intended association into a small contract that can be reviewed beside the ARM export. Sort keys before hashing so formatting differences do not look like drift.

json 03-expected-job-schedule.json
{
"schedule": "nightly-maintenance",
"runbook": "Invoke-NightlyMaintenance",
"runOn": "hrw-prod-eu",
"parameters": {
  "Environment": "prod",
  "Mode": "Apply",
  "SubscriptionId": "<production-subscription-id>"
}
}

Compare this contract with the deployed association, the infrastructure-as-code source and one known-good execution. The important questions are concrete:

  • Is there exactly one intended production association for this schedule and runbook?
  • Are parameter names, casing, types and environment values identical?
  • Does runOn name an active Hybrid Worker group with the expected runtime and identity?
  • Is the schedule enabled, unexpired and evaluated in the expected timezone?
  • Can the run duration overlap the next recurrence or a second staggered schedule?
  • Did a deployment recreate the association under a new UUID while leaving the old one active?

An association can drift while the schedule and runbook both appear unchanged. That is why a code diff alone is insufficient evidence.

Reconstruct what the jobs actually did

Use the last healthy job and the first faulty job as controls. Preserve their IDs, creation and start times, status, worker target, input parameters, output and error streams. Then verify the target system independently: a completed Automation job is not proof that every intended resource changed, and a failed job may already have applied a partial effect.

If Automation job logs and streams are sent to Log Analytics, use a bounded window and adapt the schema to the configured tables.

kusto 04-compare-scheduled-jobs.kql
let Start = datetime(2026-11-10T00:30:00Z);
let End = datetime(2026-11-12T02:30:00Z);
AzureDiagnostics
| where TimeGenerated between (Start .. End)
| where ResourceProvider == "MICROSOFT.AUTOMATION"
| where RunbookName_s == "Invoke-NightlyMaintenance"
| project TimeGenerated,
        Category,
        JobId_g,
        RunbookName_s,
        ResultType,
        ResultDescription,
        CorrelationId
| order by TimeGenerated asc

Correlate the Automation job ID with application, Azure Activity or target audit logs. If two jobs started from different association IDs but acted on the same target, contain duplication before repairing configuration. If no job exists, diagnose schedule and association state before touching the runbook.

Prove the candidate association with a no-effect canary

Do not validate by waiting for the next production window. Create an isolated one-time canary schedule or an equivalent disposable association using the candidate parameters and the same runOn target. The runbook needs a deterministic no-effect mode that resolves identity, enumerates the bounded target set and emits a release marker without changing state.

yaml 05-job-schedule-canary-gates.yml
candidate:
schedule: canary-maintenance-once
runbook: Invoke-NightlyMaintenance
runOn: hrw-prod-eu
parameters:
  Environment: prod
  Mode: Validate
  SubscriptionId: <production-subscription-id>

promotion_gates:
jobs_started: 1
expected_worker_group: true
expected_execution_identity: true
expected_subscription: true
target_inventory_matches_baseline: true
state_changes: 0
errors_or_warnings_unexplained: 0

cleanup:
- preserve canary job ID and streams
- remove disposable association and schedule
- verify no second job was queued

A manual run with the same values is useful for isolating code, but the canary must exercise the association to prove parameter serialization and runOn. Give it a unique correlation value and verify that exactly one job was created.

Repair between two execution windows

Treat the association as a versioned contract. Prepare the replacement payload, obtain review, choose a window after the current job has ended and before the next schedule occurrence, then recreate the association with a new UUID. Avoid a period where old and new associations can both start production work.

For a shared schedule, leave the schedule itself intact and change only the affected association. For an unshared schedule under incident containment, temporarily disabling it can be appropriate, but record the previous enabled state and next run. After the repair, export the deployed association again and compare its normalized form with the approved candidate.

The production validation should prove:

  • one expected job starts at the next occurrence;
  • no old association creates a second job;
  • parameters and worker group match the approved contract;
  • the runbook release marker matches the published artifact;
  • the target-side audit shows only the bounded intended effect;
  • alerting covers missed, duplicate, failed and overlong jobs.

Do not compensate for a stale association by adding environment-specific defaults to the runbook. That hides deployment drift inside application logic and makes manual, webhook and scheduled starts behave differently.

Decide keep, repair, suspend or roll back

Keep the deployed association when its normalized contract matches the approved state, one expected job was created and target evidence proves the failure is elsewhere. Continue diagnosis in published code, worker runtime, identity or downstream dependencies.

Repair the association when parameters, schedule binding or runOn differ and the no-effect canary passes. Promote the exact reviewed contract, then observe one real occurrence before closing the change.

Suspend the affected path when the next run is imminent, the schedule is shared and ownership is unclear, duplicate associations exist, or the runbook cannot offer a no-effect validation mode. Prefer a targeted association change; disable the whole schedule only with the impact on every linked runbook understood.

Roll back by restoring the last known association contract, not by republishing arbitrary code. If a faulty job already changed resources, use the target system’s tested compensation runbook separately. Restoring the trigger prevents future executions; it does not undo an external effect.

Conclusion

In Azure Automation, a schedule is not the full execution contract. The operational boundary is the jobSchedule that joins recurrence, published runbook, parameters and worker target, then produces a job whose effects must be verified outside Automation.

The decision becomes defensible when those objects are reconciled independently: keep a proven association, recreate only the drifted binding, suspend an ambiguous next run, or restore the last known contract. Changing working code is not a substitute for diagnosing the trigger that actually ran it.