Senior 3 min · March 19, 2026

AutoSys Global Variables — Stale Flags That Skip Batch Runs

Global variables persist until explicitly reset.

N
Naren · Founder
Plain-English first. Then code. Then the interview question.
About
 ● Production Incident 🔎 Debug Guide
Quick Answer
  • Global variables are name-value pairs stored in the Event Server — any job can read or write them
  • Set from a job: sendevent -E SET_GLOBAL -G "COUNT=5432" inside your script
  • Read in JIL conditions: variable(TRADING_COUNT) >= 1 — data-driven scheduling
  • Read from command line: autostatus -G TRADING_COUNT
  • Production killer: globals persist between runs. Monday's COMPLETE flag is still COMPLETE on Tuesday. Reset at workflow start, not end.
  • Naming convention: TRADING_RECORD_COUNT, not COUNT. Instance-wide — collisions cause silent failures.
Plain-English First

Global variables in AutoSys are like a shared whiteboard in a team's office. Any job can write a value on the board, and any other job can read what's written. Jobs use this to pass information forward in a pipeline — like 'I processed 5,432 records, here's the count for your use.'

AutoSys global variables live in the Event Server. Any job can read them. Any job can write them. They persist until explicitly changed.

That last sentence is where teams get burned.

A flag set to 'COMPLETE' on Monday is still 'COMPLETE' on Tuesday. A counter that reached 5000 yesterday is still 5000 today unless you reset it. This article covers the patterns that work — and the one stale-value trap that breaks workflows silently.

Setting a global variable from a job

Jobs set global variables using the sendevent command with the SET_GLOBAL event. This can be done from within the job's script or from the command line.

The syntax is: sendevent -E SET_GLOBAL -G "VARNAME=value". No spaces around the equals sign.

Critical: SET_GLOBAL events are processed asynchronously. There's a small delay (typically <1 second) between the command and the value being readable by other jobs. If your downstream job starts immediately after setting a variable, it might not see the value yet. Use condition dependencies to enforce order if timing matters.

set_global.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/bash
# Script that processes records and sets the count as a global variable

RECORD_COUNT=$(wc -l < /data/processed_trades.csv)

# Set the global variable in AutoSys
sendevent -E SET_GLOBAL -G "TRADE_COUNT=${RECORD_COUNT}"

# For workflows with date-stamped globals (recommended for daily runs)
DATE=$(date +%Y%m%d)
sendevent -E SET_GLOBAL -G "TRADE_COUNT_${DATE}=${RECORD_COUNT}"

echo "Processed ${RECORD_COUNT} trades, set TRADE_COUNT global variable"
exit 0
Output
Processed 5432 trades, set TRADE_COUNT global variable
/* AutoSys: Global variable TRADE_COUNT set to 5432 */
/* AutoSys: Global variable TRADE_COUNT_20260319 set to 5432 */
The Shared Whiteboard Model
  • Write: sendevent -E SET_GLOBAL -G "NAME=VALUE" — from any job or command line
  • Read: autostatus -G NAME — returns current value
  • Clear: sendevent -E SET_GLOBAL -G "NAME=" — empty string removes it
  • The board persists across days, weeks, restarts. No automatic expiry.
Production Insight
A job set a global variable for downstream consumption. The downstream job had a condition variable(DATA_READY) = 1. The setting job succeeded. The downstream job didn't start.
The issue: The downstream job started at the exact same second as the SET_GLOBAL event was sent. AutoSys processes events sequentially, but condition re-evaluation happens after the event queue settles. The downstream job's check ran before the global was written.
Fix: Add a 5-second sleep in the setting job after the sendevent, or use an intermediate job that does nothing but wait 10 seconds.
Diagnosis: Check job start timestamps in autorep -d. If they're within the same second, you have a race condition.
Rule: SET_GLOBAL is asynchronous. Don't assume the value is readable immediately.
Key Takeaway
SET_GLOBAL writes to Event Server — asynchronous, not instant.
Use condition dependencies to order setting and reading jobs.
Date-stamped globals (COUNT_20260319) prevent stale-value bugs.
Clear with empty string: sendevent -E SET_GLOBAL -G "NAME=".
Global Variable Lifecycle Global Variable Lifecycle. Set · read · reset pattern · RESET job runs first · sendevent SET_GLOBAL COUNTER=0 · Processing job runs · script processes records · Script sets global THECODEFORGE.IOGlobal Variable LifecycleSet · read · reset pattern RESET job runs firstsendevent SET_GLOBAL COUNTER=0 Processing job runsscript processes records Script sets globalsendevent SET_GLOBAL COUNTER=5432 Downstream job reads itautostatus -G COUNTER condition: variable() checkcondition: variable(COUNTER) >= 1THECODEFORGE.IO
thecodeforge.io
Global Variable Lifecycle
Autosys Global Variables

Reading a global variable in a JIL condition

You can reference global variables in JIL conditions using the variable() function. This lets you create data-driven conditions.

Syntax: condition: success(job_a) AND variable(TRADE_COUNT) >= 1000 The comparison operators work: =, !=, <, >, <=, >=. String comparison works too: variable(STATUS) = 'COMPLETE'

Critical: variable() returns an empty string if the global doesn't exist. In numerical comparisons, empty string compares as 0. That can cause false positives — a missing variable might silently pass a >=1 check.

global_in_condition.jilBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* Read a global variable in a condition */
insert_job: validate_trade_count
job_type: CMD
command: "/scripts/validate_count.sh ${TRADE_COUNT}"
machine: server01
owner: batch
condition: success(process_trades) AND variable(TRADE_COUNT) >= 1

/* String comparison with global */
insert_job: check_status
job_type: CMD
condition: variable(WORKFLOW_STATUS) = 'READY'

/* Dangerous: missing global passes >= 0 check */
/* If TRADE_COUNT never set, this condition is TRUE */
condition: variable(TRADE_COUNT) >= 0

/* Safer: check existence and value */
condition: variable(TRADE_COUNT) != '' AND variable(TRADE_COUNT) >= 100

/* Set a global variable via sendevent from command line */
# sendevent -E SET_GLOBAL -G "PROCESS_DATE=20260319"

/* Check current value of a global variable */
# autostatus -G TRADE_COUNT
Output
TRADE_COUNT = 5432
Missing global variables evaluate as empty string — not an error
variable(MISSING_GLOBAL) returns ''. In a numeric comparison like >= 0, '' is treated as 0. Your condition will pass even though the variable was never set. Always check for existence first: variable(COUNT) != '' AND variable(COUNT) >= 100.
Production Insight
A downstream job had condition: variable(FILE_COUNT) >= 5. The upstream job that set FILE_COUNT failed silently. FILE_COUNT never got set. variable(FILE_COUNT) returned '' which AutoSys treated as 0. 0 >= 5 is false, so the condition didn't fire. The workflow stopped. No error. No alert.
The team assumed the condition would error if the variable was missing. It doesn't.
Fix: Change condition to: variable(FILE_COUNT) != '' AND variable(FILE_COUNT) >= 5. Now missing variable fails the condition and can trigger alarms.
Better: Add a validation job that explicitly checks that expected globals are set before downstream runs.
Rule: variable() never errors. It returns ''. Build explicit existence checks into your conditions.
Key Takeaway
variable(NAME) returns '' if NAME doesn't exist — no error.
Always check existence: variable(NAME) != '' before comparing values.
String comparisons work: variable(STATUS) = 'READY'
Numerical comparisons treat '' as 0 — use existence check to avoid false positives.

Global variable naming, lifecycle, and best practices

Global variables persist in the Event Server until explicitly changed or cleared. They do not reset between daily runs — a value set yesterday is still there today unless something overwrites it. This is both powerful and dangerous.

Lifecycle: Created on first SET_GLOBAL. Persists indefinitely. Cleared by SET_GLOBAL with empty value (or by database cleanup). Survives Event Processor restarts, failovers, and system reboots.

Best practices that separate senior engineers from beginners: 1. Always use a naming convention with a workflow prefix (e.g., TRADING_RECORD_COUNT not just COUNT) 2. Reset flags and counters at the start of each workflow run, not the end 3. For per-run state, include the date in the variable name (e.g., TRADING_COUNT_20260319) 4. Document every global variable your workflow uses — undocumented globals become tribal knowledge 5. Audit global variables monthly with autostatus -G % to catch stale or orphaned ones 6. Never assume a global exists. Check before reading.

global_var_lifecycle.shBASH
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# PATTERN: Reset globals at the START of a workflow (not end)
# Add this as the first job in your box:

insert_job: PRD_TRADING_RESET_GLOBALS
job_type: CMD
box_name: PRD_TRADING_EOD_BOX
command: /scripts/reset_trading_globals.sh
machine: server01
owner: batch
# No condition — first job in box

# reset_trading_globals.sh contents:
# sendevent -E SET_GLOBAL -G "TRADING_RECORD_COUNT=0"
# sendevent -E SET_GLOBAL -G "TRADING_STATUS_FLAG="
# sendevent -E SET_GLOBAL -G "TRADING_PROCESS_DATE=$(date +%Y%m%d)"

# PATTERN: Date-stamped globals for per-run state
DATE=$(date +%Y%m%d)
sendevent -E SET_GLOBAL -G "TRADING_COUNT_${DATE}=5432"
# Downstream job reads: variable(TRADING_COUNT_20260319)

# List all current global variables
autostatus -G %

# Clear a stale global
sendevent -E SET_GLOBAL -G "STALE_FLAG="
Output
TRADING_RECORD_COUNT = 0
TRADING_STATUS_FLAG =
TRADING_PROCESS_DATE = 20260319
TRADING_COUNT_20260319 = 5432
Total globals: 12
Globals do not reset between daily runs — this is the #1 bug
Set a flag to 'COMPLETE' on Monday. Tuesday morning, it's still 'COMPLETE'. Your check at the start of Tuesday's workflow will see 'COMPLETE' and exit early. Always reset globals at the START of each run, not at the end. The reset job is the first job in your box, unconditionally.
Production Insight
A team had 47 global variables in their instance after 3 years of batch workflows. 31 of them were stale — values from workflows that no longer existed, or from runs months ago. No one knew what they were for. Some were still being read by active workflows, causing intermittent bugs when stale values collided with new runs.
The audit: autostatus -G % showed all variables. The team exported them to a spreadsheet. For each variable, they asked: 'What workflow sets this? What workflow reads this? When was it last updated?'
If no one could answer, they cleared it.
After cleanup, 12 variables remained — all documented in a shared wiki with owners, reset patterns, and expected values.
Fix: Add a monthly audit job that lists all globals and flags any last-updated > 30 days ago (requires custom tracking — AutoSys doesn't store timestamps natively, but you can write a wrapper script that logs SET_GLOBAL events).
Rule: Orphaned globals are technical debt. Audit quarterly. Clear what you can't explain.
Key Takeaway
Globals persist forever — reset at workflow START, not end.
Date-stamped names prevent stale-value bugs entirely.
Audit globals quarterly. autostatus -G % shows everything.
Document naming convention: WORKFLOW_PURPOSE (e.g., TRADING_RECORD_COUNT).
Global variable naming and lifecycle decisions
IfValue must persist across workflow runs (e.g., max counter since deployment)
UseSimple name: TOTAL_RECORDS_PROCESSED. Reset never. Only append.
IfValue is per-run state (e.g., today's record count)
UseDate-stamped name: TRADING_COUNT_20260319. No reset needed — each day is unique.
IfValue is a flag that controls workflow behavior (e.g., SKIP_FLAG)
UseReset at START of each run, not end. First job in box clears the flag.
IfValue is shared across multiple workflows
UseUse workflow prefix + shared: TRADING_SHARED_LATEST_FILE. Document in both teams' wikis.
● Production incidentPOST-MORTEMseverity: high

The Stale Flag That Skipped a Day of Processing

Symptom
Daily batch jobs show SUCCESS in autorep. Downstream systems report no new data. Batch runtime is suspiciously short — minutes instead of hours. No errors in any logs.
Assumption
The team assumed global variables reset between daily runs. They didn't know globals persist forever unless explicitly cleared or overwritten.
Root cause
The workflow pattern was: 1. Check FLAG at start. If DONE, exit. 2. Process data. 3. Set FLAG='DONE' at end. Monday: FLAG was empty → processed → set FLAG='DONE'. Tuesday: FLAG was still 'DONE' → exited at step 1. The flag was never reset. The workflow checked a condition that persisted from the previous day. No one had documented that globals don't auto-reset.
Fix
1. Change pattern: reset at START, not at end. - First job in box: sendevent -E SET_GLOBAL -G "DAILY_FLAG=" (clear it) - Then run main processing - No need to set DONE at end — the next day's reset handles it 2. Add date stamp to flag: FLAG_20260319='DONE' — each run has unique name 3. Monitor: script that alerts if flag is > 24 hours old without a matching run 4. Document: 'Global variables persist until overwritten. Reset at start of each workflow.'
Key lesson
  • Global variables persist in the Event Server until explicitly changed.
  • Reset at workflow START, not end. A stale flag from yesterday kills today's run.
  • Use date-stamped global names for per-run state: TRADING_COUNT_20260319.
  • Audit global variables weekly with autostatus -G % to catch stale values.
Production debug guideIf your workflow is skipping or behaving strangely, check your globals first4 entries
Symptom · 01
Workflow runs but does no work — completes in seconds. Expected data missing.
Fix
Check global flags that control early exit. autostatus -G WORKFLOW_FLAG. If flag is 'DONE' or 'SKIP', your start-of-run reset job likely failed or never ran.
Symptom · 02
Job condition with variable(COUNT) >= 1 never triggers even though COUNT is high
Fix
Check COUNT value: autostatus -G TRADING_COUNT. If COUNT is 0, the setting job may have failed. If COUNT is from yesterday, your reset logic is clearing it too late (at end instead of start).
Symptom · 03
Different workflows interfering with each other's globals
Fix
List ALL globals: autostatus -G %. Look for naming collisions. Fix: rename with workflow prefix. TEAM1_COUNT and TEAM2_COUNT don't collide. COUNT does.
Symptom · 04
Global variable set in job doesn't persist to next job in box
Fix
Check if the setting job succeeded (autorep -J JOB). If it failed, no SET_GLOBAL event was sent. Also check order: setting job must complete before reading job starts — use condition dependencies.
★ Global Variables — 60-Second DiagnosisWhen workflows skip, conditions don't fire, or values look wrong
Workflow skipped — ran too fast, no output
Immediate action
Check early-exit global flags
Commands
autostatus -G % | grep -E 'FLAG|STATUS|DONE'
autorep -J WORKFLOW_START_JOB -L 5 | grep SET_GLOBAL
Fix now
sendevent -E SET_GLOBAL -G "WORKFLOW_FLAG="
Condition with variable() not triggering+
Immediate action
Check global value and condition syntax
Commands
autostatus -G TRADING_COUNT
autorep -J DOWNSTREAM_JOB -q | grep condition
Fix now
sendevent -E SET_GLOBAL -G "TRADING_COUNT=100"
Stale value from yesterday still present+
Immediate action
Check last modified time (if available) or value reasonableness
Commands
autostatus -G DAILY_COUNTER
echo "Expected counter for $(date +%Y%m%d) vs actual"
Fix now
sendevent -E SET_GLOBAL -G "DAILY_COUNTER=0"
Can't find what globals exist+
Immediate action
List all globals, filter by workflow
Commands
autostatus -G % | grep WORKFLOW_PREFIX
autostatus -G % | wc -l
Fix now
Document naming convention and audit monthly
Global Variable Operations — Quick Reference
OperationCommandExampleNotes
Set a global variablesendevent -E SET_GLOBALsendevent -E SET_GLOBAL -G "COUNT=100"No spaces around =. Async — slight delay before readable.
Check a global variable valueautostatus -G varnameautostatus -G TRADE_COUNTReturns empty string if variable doesn't exist.
Reference in JIL conditionvariable(varname)condition: variable(FLAG) = 1Returns '' if missing. Always check existence first.
Clear a global variablesendevent -E SET_GLOBALsendevent -E SET_GLOBAL -G "FLAG="Empty value removes the variable from the Event Server.
List all global variablesautostatus -G %autostatus -G %Use for audits and debugging stale values.

Key takeaways

1
Global variables persist in the Event Server forever
until explicitly cleared. Reset at workflow START, not end.
2
Use workflow prefixes
TRADING_COUNT, PAYMENT_COUNT. Instance-wide = collisions without prefixes.
3
variable() returns '' for missing variables, not error. Always check existence in conditions.
4
Date-stamped names (COUNT_20260319) prevent stale-value bugs entirely
each run is unique.
5
SET_GLOBAL is asynchronous. Don't assume immediate readability. Use condition ordering.
6
Audit globals quarterly with autostatus -G %. Orphaned variables are technical debt.

Common mistakes to avoid

5 patterns
×

Using short, generic variable names without workflow prefix

Symptom
Two teams use COUNT in different workflows. One workflow sets COUNT=100. The other reads COUNT and expects a different value. Silent data corruption — jobs run with wrong thresholds.
Fix
Use workflow prefix: TRADING_COUNT, PAYMENT_COUNT, REPORTING_COUNT. Globals are instance-wide. Prefixes are mandatory in production.
×

Not resetting globals between runs — resetting at end instead of start

Symptom
Monday: workflow sets FLAG='DONE' after processing. Tuesday: FLAG still 'DONE' at start. Workflow checks FLAG, sees 'DONE', exits immediately. No data processed. No error. Empty dashboard.
Fix
Reset at START. First job in your workflow clears all globals it will use. Reset job runs unconditionally as the first step.
×

Not checking existence before reading globals in conditions

Symptom
Condition: variable(TRADE_COUNT) >= 100. Upstream job that sets TRADE_COUNT fails silently. variable() returns '' which compares as 0. Condition fails (0 >= 100 is false). Workflow stops. No alert — condition just didn't fire.
Fix
Always check existence: condition: variable(TRADE_COUNT) != '' AND variable(TRADE_COUNT) >= 100.
×

Assuming SET_GLOBAL is instantly readable by downstream jobs

Symptom
Job A sets COUNT=100 then finishes. Job B with condition: variable(COUNT) >= 1 starts immediately and sees COUNT='' because the SET_GLOBAL event hasn't been fully processed yet. Race condition.
Fix
Add explicit ordering: Job A completes, then an intermediate wait job (sleep 5 seconds), then Job B. Or use condition: success(Job A) AND variable(COUNT) >= 1 — AutoSys re-evaluates after the event finishes.
×

Not documenting globals — undocumented globals become tribal knowledge

Symptom
Senior engineer leaves. No one knows what GLOBAL_STATUS_FLAG controls. Workflow breaks. Team spends days reverse-engineering the flag's purpose. Eventually rebuilds it incorrectly.
Fix
Document every global variable in a shared wiki: owner, purpose, expected values, when it's set, when it's read, reset pattern. Audit quarterly.
INTERVIEW PREP · PRACTICE MODE

Interview Questions on This Topic

Q01JUNIOR
What is a global variable in AutoSys?
Q02JUNIOR
How do you set a global variable from an AutoSys job's script?
Q03JUNIOR
How do you read the current value of an AutoSys global variable?
Q04SENIOR
What naming convention would you use for AutoSys global variables?
Q05JUNIOR
What event type is used to set a global variable in AutoSys?
Q06SENIOR
How do you prevent stale global variables from breaking workflows betwee...
Q01 of 06JUNIOR

What is a global variable in AutoSys?

ANSWER
A global variable is a name-value pair stored in the Event Server that can be read and written by any job in the AutoSys instance at runtime. Key characteristics: - Persists until explicitly cleared or overwritten - Survives Event Processor restarts and system reboots - Accessible via sendevent SET_GLOBAL (write), autostatus (read), and variable() in JIL conditions - Instance-wide — no isolation between different workflows or teams Use cases: Passing record counts, file paths, status flags, or control parameters between jobs in a pipeline.
FAQ · 6 QUESTIONS

Frequently Asked Questions

01
What are global variables in AutoSys?
02
How do I set a global variable in AutoSys?
03
How do I check the value of an AutoSys global variable?
04
Are global variables shared across all AutoSys jobs?
05
Do global variables persist between runs?
06
What happens if I reference a global variable that doesn't exist in a condition?
COMPLETE GUIDE
The Complete AutoSys Workload Automation Guide for Engineers →

JIL syntax, sendevent, autorep, box jobs, file watchers, scheduling, HA, security, cloud workload automation, and 22 interview questions — the definitive AutoSys reference for production engineers.

🔥

That's AutoSys. Mark it forged?

3 min read · try the examples if you haven't

Previous
AutoSys Calendars and run_calendar
16 / 30 · AutoSys
Next
AutoSys date_conditions and run_window