Skip to content
Aaron Crow edited this page May 23, 2013 · 10 revisions

Variables in a workflow

Drake lets you define and use variables throughout your workflow.

Here's a simple example of defining, then using, a variable in a simple workflow:

MYVAR=some_value

out.txt <- in.txt
  echo $[MYVAR]

The first line defines the value of MYVAR. The $[MYVAR] syntax tells Drake to substitute the value of MYVAR before interpreting the rest of the step.

There is also a conditional definition, :=, for variables. For example:

MYVAR:=some_value
...

The := operator tells Drake to only set the value of MYVAR to some_value if MYVAR is not already defined. (We'll talk later about ways to define variables outside of the workflow.)

Here's another example, this time setting up a kind of profiles concept for our workflow:

PROFILE:=default_profile
%include $[PROFILE]

out.txt <- $[INFILE]
  echo $[MYVAR]

The above example assumes we've organized a set of variables into profile files, such as a file called default_profile. The workflow uses %include to pull that file in, thereby allowing that file to define its custom values for our variables. Our workflow then makes use of those variables, such as INFILE and MYVAR.

An example default_profile file would be like:

INFILE=in.json
MYVAR=some_other_value

Defining variables outside the workflow

There are two ways to pass variables to a Drake workflow:

  1. Define environment variables before running the workflow
  2. Set variables via the --vars command line option

Further reading

Please see the official spec for more details on the use of variables with Drake.