AutoSys Global Variables — Sharing Data Between Jobs
- Global variables are instance-wide name-value pairs stored in the Event Server — any job can read or write them
- Set globals with
sendevent -E SET_GLOBAL -G "NAME=VALUE"from scripts or the command line - Read current values with
autostatus -G varname
AutoSys global variables are name-value pairs stored in the Event Server that any job can read and write at runtime. They're the primary mechanism for passing data between jobs in a batch pipeline — processing counts, file paths, status flags, dates.
This is a feature that's easy to misuse (overusing globals creates hidden dependencies), but when used well it's powerful.
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.
#!/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}" echo "Processed ${RECORD_COUNT} trades, set TRADE_COUNT global variable" exit 0
/* AutoSys: Global variable TRADE_COUNT set to 5432 */
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.
/* 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 /* 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
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.
Best practices: 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. Document every global variable your workflow uses — undocumented globals become tribal knowledge 4. Audit global variables periodically with autostatus to catch stale or orphaned ones
# 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=PENDING" # sendevent -E SET_GLOBAL -G "TRADING_PROCESS_DATE=$(date +%Y%m%d)" # List all current global variables autostatus -G %
TRADING_STATUS_FLAG = PENDING
TRADING_PROCESS_DATE = 20260319
| Operation | Command | Example |
|---|---|---|
| Set a global variable | sendevent -E SET_GLOBAL | sendevent -E SET_GLOBAL -G "COUNT=100" |
| Check a global variable value | autostatus -G varname | autostatus -G TRADE_COUNT |
| Reference in JIL condition | variable(varname) | condition: variable(FLAG) = 1 |
| Clear a global variable | sendevent -E SET_GLOBAL | sendevent -E SET_GLOBAL -G "FLAG=" |
🎯 Key Takeaways
- Global variables are instance-wide name-value pairs stored in the Event Server — any job can read or write them
- Set globals with
sendevent -E SET_GLOBAL -G "NAME=VALUE"from scripts or the command line - Read current values with
autostatus -G varname - Use a naming convention with workflow prefix to avoid collision between teams
⚠ Common Mistakes to Avoid
- ✕Using short, generic variable names that collide with other teams' globals — always use a naming convention with workflow prefix
- ✕Not clearing global variables between runs — a job that checks a flag global might pick up the value from the previous day's run
- ✕Setting globals without documenting them — undocumented globals become tribal knowledge that causes problems when team members leave
- ✕Reading a global that hasn't been set yet — autostatus returns empty; ensure the setting job always runs first
Interview Questions on This Topic
- QWhat is a global variable in AutoSys?
- QHow do you set a global variable from an AutoSys job's script?
- QHow do you read the current value of an AutoSys global variable?
- QWhat naming convention would you use for AutoSys global variables?
- QWhat event type is used to set a global variable in AutoSys?
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.
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.
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.
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 important: use workflow-specific prefixes to avoid conflicts between different teams' jobs.
Do global variables persist between runs?
Yes. Global variable values persist in the Event Server until explicitly changed or cleared. 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.
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.