createTask

Creates a new Snowflake task with comprehensive configuration options including schedule, warehouse assignment, tags, contacts, session parameters, predecessors, conditional execution, and finalize tasks.

Note: Automatic rollback drops the task.

Known limitation: This change type does not support database inspection features (snapshot, diff, diff-changelog, and generate-changelog commands).

Available attributes

Name

Type

Description

Required

catalogName

String

Name of the catalog (database) where the task will be created

No

schemaName

String

Name of the schema where the task will be created

No

taskName

String

Name of the task to create

Yes

replaceIfExists

Boolean

If true, replaces the task if it already exists using OR REPLACE

No*

alterIfExists

Boolean

If true, alters the task if it already exists using OR ALTER

No*

ifNotExists

Boolean

If true, only creates the task if it doesn't exist using IF NOT EXISTS

No*

warehouse

String

Warehouse to use for executing the task

No

userTaskManagedInitialWarehouseSize

String

Initial warehouse size for serverless tasks (e.g., XSMALL, SMALL)

No

schedule

String

Schedule for automatic execution (e.g., 10 MINUTES, USING CRON 0 9 * * * UTC)

No

config

String

JSON configuration string for task settings

No

allowOverlappingExecution

Boolean

If true, allows multiple instances of the task to run concurrently

No

errorIntegration

String

Notification integration to call when task encounters errors

No

successIntegration

String

Notification integration to call when task completes successfully

No

comment

String

Comment describing the task

No

finalize

String

Name of root task this task finalizes

No

targetCompletionInterval

String

Target interval for task completion (e.g., 5 MINUTES)

No

executeAsUser

String

User context for task execution (TASK_OWNER or CALLER)

No

whenClause

String

SQL condition that must be true for task to execute

No

asClause

String

SQL statement to execute when task runs

Yes

after

Nested

List of predecessor tasks that must complete first

No

tags

Nested

Key-value pairs of tags to apply

No

contacts

Nested

Key-value pairs mapping contact purposes to contact names

No

sessionParameters

Nested

Session parameters to set when task executes

No

*Only one of replaceIfExists, alterIfExists, or ifNotExists can be true.

One of warehouse or userTaskManagedInitialWarehouseSize must be specified.

Root tasks (without predecessors) must have either schedule or finalize specified.

Child tasks (tasks with after predecessors) cannot have a schedule.

Maximum of 100 predecessor tasks allowed in the after list.

Valid values for userTaskManagedInitialWarehouseSize: XSMALL, SMALL, MEDIUM, LARGE, XLARGE, XXLARGE, XXXLARGE, X4LARGE, X5LARGE, X6LARGE.

Nested elements

after - List of predecessor tasks that must complete before this task runs:

Element

Description

afterTask

Element with taskName attribute

tags (MapWrapper) - Key-value pairs of tags to apply to the task. Tags must exist before being referenced.

contacts (MapWrapper) - Key-value pairs mapping contact purposes to contact names. Valid purposes: Steward, Approver, Support. Contacts must exist before being referenced.

sessionParameters (MapWrapper) - Session parameters to set when task executes (e.g., QUERY_TAG).

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
  xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
  xmlns:pro-snowflake="http://www.liquibase.org/xml/ns/pro-snowflake"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
        http://www.liquibase.org/xml/ns/pro-snowflake
        http://www.liquibase.org/xml/ns/pro-snowflake/liquibase-pro-snowflake-latest.xsd">
  <!-- Simple task with schedule -->
  <changeSet id="create-simple-task" author="examples">
    <pro-snowflake:createTask
            taskName="SIMPLE_TASK"
            warehouse="MY_WH"
            schedule="10 MINUTES"
            comment="Simple scheduled task">
      <pro-snowflake:asClause>SELECT 1 AS result</pro-snowflake:asClause>
    </pro-snowflake:createTask>
  </changeSet>
  <!-- Root task with tags, contacts, and session parameters -->
  <changeSet id="create-root-task" author="examples">
    <pro-snowflake:createTask
            taskName="ROOT_TASK"
            warehouse="MY_WH"
            schedule="10 MINUTES"
            comment="Root task for task graph">
      <pro-snowflake:tags>
        <pro-snowflake:entry key="environment" value="production"/>
        <pro-snowflake:entry key="owner" value="data_team"/>
      </pro-snowflake:tags>
      <pro-snowflake:contacts>
        <pro-snowflake:entry key="Support" value="support_contact"/>
      </pro-snowflake:contacts>
      <pro-snowflake:sessionParameters>
        <pro-snowflake:entry key="QUERY_TAG" value="root_task"/>
      </pro-snowflake:sessionParameters>
      <pro-snowflake:asClause>SELECT 1 AS result</pro-snowflake:asClause>
    </pro-snowflake:createTask>
  </changeSet>
  <!-- Child task with predecessor and conditional execution -->
  <changeSet id="create-child-task" author="examples">
    <pro-snowflake:createTask
            taskName="CHILD_TASK"
            warehouse="MY_WH">
      <pro-snowflake:after>
        <pro-snowflake:afterTask taskName="ROOT_TASK"/>
      </pro-snowflake:after>
      <pro-snowflake:whenClause>SYSTEM$GET_PREDECESSOR_RETURN_VALUE('ROOT_TASK') = 1</pro-snowflake:whenClause>
      <pro-snowflake:asClause>SELECT 2 AS result</pro-snowflake:asClause>
    </pro-snowflake:createTask>
  </changeSet>
  <!-- Finalizer task for cleanup -->
  <changeSet id="create-finalizer-task" author="examples">
    <pro-snowflake:createTask
            taskName="CLEANUP_TASK"
            finalize="ROOT_TASK">
      <pro-snowflake:asClause>CALL cleanup_procedure()</pro-snowflake:asClause>
    </pro-snowflake:createTask>
  </changeSet>
  <!-- Serverless task (no warehouse) -->
  <changeSet id="create-serverless-task" author="examples">
    <pro-snowflake:createTask
            taskName="SERVERLESS_TASK"
            userTaskManagedInitialWarehouseSize="XSMALL"
            schedule="5 MINUTES">
      <pro-snowflake:asClause>SELECT CURRENT_TIMESTAMP</pro-snowflake:asClause>
    </pro-snowflake:createTask>
  </changeSet>
  <!-- Task with CRON schedule -->
  <changeSet id="create-cron-task" author="examples">
    <pro-snowflake:createTask
            taskName="DAILY_TASK"
            warehouse="MY_WH"
            schedule="USING CRON 0 9 * * * America/Los_Angeles">
      <pro-snowflake:asClause>CALL daily_report()</pro-snowflake:asClause>
    </pro-snowflake:createTask>
  </changeSet>
</databaseChangeLog>