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.
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

Change the name of a task depending on environment

In this example, we interpolate the environment variable directly into the task name.
javascript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "hello_world",
6
name: `Hello world in environment ${process.env.AIRPLANE_ENV_SLUG}`,
7
},
8
async () => {
9
return "Hello, world!";
10
},
11
);

Set different schedules depending on environment

Here, we create a schedule that runs weekly in all environments except prod, where it runs daily.
javascript
Copied
1
import airplane from "airplane";
2
3
export default airplane.task(
4
{
5
slug: "hello_world",
6
name: "Hello World",
7
schedules:
8
process.env.AIRPLANE_ENV_SLUG === "prod"
9
? {
10
prod_midnight_daily: {
11
cron: "0 0 * * *",
12
},
13
}
14
: {
15
dev_weekly: {
16
cron: "0 0 * * 1",
17
},
18
},
19
},
20
() => {
21
return "Hello, world!";
22
},
23
);