{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"redocly_category":"Products","product_name":"Data Workbench","type":"markdown"},"seo":{"title":"Defining Variables","description":"Treasure Data Product Documentation · Collect and Unify · Segment and Activate · Experiment and Analyze · Decisioning Automate with AI Scale and Trust.","siteUrl":"https://docs.treasuredata.com","lang":"en-US","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"defining-variables","__idx":0},"children":["Defining Variables"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can define variables:"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Using ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["_export"]}," parameter in YAML"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Starting a session with variables"]}]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"_export","__idx":1},"children":["_export:"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["In a YAML file, the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["_export:"]}," directive defines variables. This is useful to load static configurations such as the host name of a database."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"warning","name":"Limitation"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Variable definitions cannot reference other variables. For example, defining a variable as ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["bar: \"${foo}_suffix\""]}," within ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["_export:"]}," is not supported."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["If a task has ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["_export"]}," directive, the task and its children can use the variables because it defines variables in a scope. With following example, all tasks can use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["foo=1"]}," but only +step1 (and +analyze) can use ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["bar="]},"."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"_export:\n  foo: 1\n\n+prepare:\n  py>: tasks.MyWorkflow.prepare\n\n+analyze:\n  _export:\n    bar: 2\n\n  +step1:\n    py>: tasks.MyWorkflow.analyze_step1\n\n+dump:\n  py>: tasks.MyWorkflow.dump\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"starting-a-session-with-variables","__idx":2},"children":["Starting a Session with Variables"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["You can set variables when you start a new workflow session."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["To set variables"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Use the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["-p KEY=VALUE"]}," multiple times."," ","For example:"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"$ td wf run -p my_var1=foo -p my_var2=abc\n","lang":"bash"},"children":[]}]},"headings":[{"value":"Defining Variables","id":"defining-variables","depth":1},{"value":"_export:","id":"_export","depth":2},{"value":"Starting a Session with Variables","id":"starting-a-session-with-variables","depth":2}],"frontmatter":{"seo":{"title":"Defining Variables"}},"lastModified":"2026-06-01T08:02:47.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/products/customer-data-platform/data-workbench/workflows/defining-variables","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}