AutoSys Global Variables: 3 Patterns That Work (and 1 That Breaks)
- Global variables persist in the Event Server forever — until explicitly cleared. Reset at workflow START, not end.
- Use workflow prefixes: TRADING_COUNT, PAYMENT_COUNT. Instance-wide = collisions without prefixes.
- variable() returns '' for missing variables, not error. Always check existence in conditions.
- 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.
Global Variables — 60-Second Diagnosis
Workflow skipped — ran too fast, no output
autostatus -G % | grep -E 'FLAG|STATUS|DONE'autorep -J WORKFLOW_START_JOB -L 5 | grep SET_GLOBALCondition with variable() not triggering
autostatus -G TRADING_COUNTautorep -J DOWNSTREAM_JOB -q | grep conditionStale value from yesterday still present
autostatus -G DAILY_COUNTERecho "Expected counter for $(date +%Y%m%d) vs actual"Can't find what globals exist
autostatus -G % | grep WORKFLOW_PREFIXautostatus -G % | wc -lProduction Incident
Production Debug GuideIf your workflow is skipping or behaving strangely, check your globals first
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.
#!/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
/* AutoSys: Global variable TRADE_COUNT set to 5432 */
/* AutoSys: Global variable TRADE_COUNT_20260319 set to 5432 */
- 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.
variable(DATA_READY) = 1. The setting job succeeded. The downstream job didn't start.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.
/* 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
variable() never errors. It returns ''. Build explicit existence checks into your conditions.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.
# 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="
TRADING_STATUS_FLAG =
TRADING_PROCESS_DATE = 20260319
TRADING_COUNT_20260319 = 5432
Total globals: 12
| Operation | Command | Example | Notes |
|---|---|---|---|
| Set a global variable | sendevent -E SET_GLOBAL | sendevent -E SET_GLOBAL -G "COUNT=100" | No spaces around =. Async — slight delay before readable. |
| Check a global variable value | autostatus -G varname | autostatus -G TRADE_COUNT | Returns empty string if variable doesn't exist. |
| Reference in JIL condition | variable(varname) | condition: variable(FLAG) = 1 | Returns '' if missing. Always check existence first. |
| Clear a global variable | sendevent -E SET_GLOBAL | sendevent -E SET_GLOBAL -G "FLAG=" | Empty value removes the variable from the Event Server. |
| List all global variables | autostatus -G % | autostatus -G % | Use for audits and debugging stale values. |
🎯 Key Takeaways
- Global variables persist in the Event Server forever — until explicitly cleared. Reset at workflow START, not end.
- Use workflow prefixes: TRADING_COUNT, PAYMENT_COUNT. Instance-wide = collisions without prefixes.
- variable() returns '' for missing variables, not error. Always check existence in conditions.
- Date-stamped names (COUNT_20260319) prevent stale-value bugs entirely — each run is unique.
- SET_GLOBAL is asynchronous. Don't assume immediate readability. Use condition ordering.
- Audit globals quarterly with autostatus -G %. Orphaned variables are technical debt.
⚠ Common Mistakes to Avoid
Interview Questions on This Topic
- QWhat is a global variable in AutoSys?JuniorReveal
- QHow do you set a global variable from an AutoSys job's script?JuniorReveal
- QHow do you read the current value of an AutoSys global variable?JuniorReveal
- QWhat naming convention would you use for AutoSys global variables?Mid-levelReveal
- QWhat event type is used to set a global variable in AutoSys?JuniorReveal
- QHow do you prevent stale global variables from breaking workflows between runs?SeniorReveal
Frequently Asked Questions
What are global variables in AutoSys?
Global variables are named values stored in the AutoSys Event Server that can be read and written by any job at runtime. They're used to pass information between jobs in a pipeline — record counts, file paths, status flags, and dates.
Key properties: persist until explicitly cleared, survive system restarts, accessible via sendevent SET_GLOBAL, autostatus -G, and in JIL conditions.variable()
How do I set a global variable in AutoSys?
Use the sendevent command: sendevent -E SET_GLOBAL -G "VARIABLE_NAME=value". This can be called from within a job's shell script, from the command line, or from another AutoSys job.
Example inside a script: ``bash COUNT=$(wc -l < /data/file.txt) sendevent -E SET_GLOBAL -G "RECORD_COUNT=${COUNT}" ``
No spaces around the equals sign. To clear a variable: sendevent -E SET_GLOBAL -G "VARIABLE_NAME=".
How do I check the value of an AutoSys global variable?
Use autostatus -G VARIABLE_NAME. This returns the current value stored in the Event Server. If the variable doesn't exist, it returns an empty string.
To list all global variables: autostatus -G %. To filter: autostatus -G % | grep TRADING.
Are global variables shared across all AutoSys jobs?
Yes. Global variables are instance-wide — they're accessible to all jobs in the AutoSys instance. This is why naming conventions are critical. Use workflow-specific prefixes (e.g., TRADING_COUNT not COUNT) to avoid collisions between different teams' jobs.
There's no namespace isolation. One workflow's STATUS variable will overwrite another workflow's STATUS variable.
Do global variables persist between runs?
Yes. Global variable values persist in the Event Server until explicitly changed or cleared. They survive Event Processor restarts, system reboots, and days of calendar time.
If you use a global as a flag that should reset each day, make sure your workflow includes a step to reset it at the START of each run (not the end). Better: use date-stamped variable names like TRADING_FLAG_20260319 so each run has its own unique variable.
What happens if I reference a global variable that doesn't exist in a condition?
variable(MISSING_VAR) returns an empty string ''. AutoSys does NOT raise an error.
In numeric comparisons, '' is treated as 0. So variable(MISSING_VAR) >= 0 evaluates as TRUE. Missing variable accidentally passes the condition.
Always check existence first: condition: variable(COUNT) != '' AND variable(COUNT) >= 100. This pattern ensures the condition only passes when the variable actually exists AND meets the threshold.
Developer and founder of TheCodeForge. I built this site because I was tired of tutorials that explain what to type without explaining why it works. Every article here is written to make concepts actually click.