Home DevOps AutoSys Global Variables — Sharing Data Between Jobs

AutoSys Global Variables — Sharing Data Between Jobs

Where developers are forged. · Structured learning · Free forever.
📍 Part of: AutoSys → Topic 16 of 30
AutoSys global variables let jobs share data at runtime.
⚙️ Intermediate — basic DevOps knowledge assumed
In this tutorial, you'll learn:
  • 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
✦ Plain-English analogy ✦ Real code with output ✦ Interview questions
⚡ Quick Answer
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 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.

set_global.sh · BASH
12345678910
#!/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
▶ Output
Processed 5432 trades, set TRADE_COUNT global variable
/* 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.

global_in_condition.jil · BASH
12345678910111213
/* 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
▶ Output
TRADE_COUNT = 5432
⚠️
Global variables are instance-wide — name carefullyGlobal variables are shared across ALL jobs in an AutoSys instance. Use a naming convention that includes the owning workflow or team: TRADING_DAILY_COUNT rather than just COUNT. Collisions between teams can cause subtle and hard-to-debug issues.

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

global_var_lifecycle.sh · BASH
123456789101112131415161718
# 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 %
▶ Output
TRADING_RECORD_COUNT = 0
TRADING_STATUS_FLAG = PENDING
TRADING_PROCESS_DATE = 20260319
⚠️
Globals do not reset between daily runsA common bug: a global set to 'COMPLETE' on Monday is still 'COMPLETE' on Tuesday when the workflow checks it. Always reset globals at the start of each run, not at the end. If the job fails mid-run and the reset job didn't run the next day, you'll start with stale values.
OperationCommandExample
Set a global variablesendevent -E SET_GLOBALsendevent -E SET_GLOBAL -G "COUNT=100"
Check a global variable valueautostatus -G varnameautostatus -G TRADE_COUNT
Reference in JIL conditionvariable(varname)condition: variable(FLAG) = 1
Clear a global variablesendevent -E SET_GLOBALsendevent -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 &quot;NAME=VALUE&quot; 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 &quot;VARIABLE_NAME=value&quot;. 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.

🔥
Naren Founder & Author

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.

← PreviousAutoSys Calendars and run_calendarNext →AutoSys date_conditions and run_window
Forged with 🔥 at TheCodeForge.io — Where Developers Are Forged