Environment-based task configuration
Dynamically modify task configuration based on the environment.
To configure a task differently based on the environment, you can use the environment variable
AIRPLANE_ENV_SLUG
, which is populated with the slug of the environment that the task is being
deployed to. (You can find the slug of your environment(s) in the
Environments settings page.)Because Airplane tasks are configured with code (see JavaScript and
Python for details), you can switch on
AIRPLANE_ENV_SLUG
to dynamically configure
schedules, constraints, and more.You can configure your task definition file (the file with extension
.task.yaml
or .task.json
)
to dynamically configure schedules, constraints, and more based on the environment that the task is
deployed to.Under the
environments
field, map an environment slug to the environment-specific configuration.
Any non-language-specific "standard" field can be configured on a per-environment basis. For
information on standard fields, see one of the Task configuration pages.yamlCopied1# my_task.task.yaml23# Configuration that applies to all environments unless overriden in the `environments` field.4name: "Hello world"56# Environment-specific configuration7environments:8prod:9name: "Hello world in environment prod"10dev:11name: "Hello world in environment dev"
Environment-based task configuration will not take effect when
Promoting tasks via the UI. A task must be
deployed into an environment for its environment-specific configuration to take effect.
Examples
Examples
Change the name of a task depending on environment
Change the name of a task depending on environment
In this example, we interpolate the environment variable directly into the task name.
javascriptCopied1import airplane from "airplane";23export default airplane.task(4{5slug: "hello_world",6name: `Hello world in environment ${process.env.AIRPLANE_ENV_SLUG}`,7},8async () => {9return "Hello, world!";10},11);
In this example, we interpolate the environment variable directly into the task name.
pythonCopied1import airplane23@airplane.task(4slug="hello_world",5name=f"Hello world in environment {os.environ.get('AIRPLANE_ENV_SLUG')}",6)7def hello_world():8return "Hello, world!"
In this example, we set a special name for the task in the
prod
environment.yamlCopied1# my_task.task.yaml2name: "Hello world"3environments:4prod:5name: "Hello world in environment prod"
Set different schedules depending on environment
Set different schedules depending on environment
Here, we create a schedule that runs weekly in all environments except
prod
, where it runs daily.javascriptCopied1import airplane from "airplane";23export default airplane.task(4{5slug: "hello_world",6name: "Hello World",7schedules:8process.env.AIRPLANE_ENV_SLUG === "prod"9? {10prod_midnight_daily: {11cron: "0 0 * * *",12},13}14: {15dev_weekly: {16cron: "0 0 * * 1",17},18},19},20() => {21return "Hello, world!";22},23);
pythonCopied1import airplane23@airplane.task(4slug="hello_world",5name="Hello World",6schedules=[(7airplane.Schedule(8slug="prod_midnight_daily",9cron="0 0 * * *",10)11if os.environ.get("AIRPLANE_ENV_SLUG") == "prod"12else airplane.Schedule(13slug="dev_weekly",14cron="0 0 * * 1",15)16)],17)18def hello_world():19return "Hello, world!"
yamlCopied1# my_task.task.yaml2schedules:3dev_weekly:4cron: "0 0 * * 1"5environments:6prod:7schedules:8midnight_daily:9cron: "0 0 * * *"