Skip to content

Environment Variables

When defining a step, one can specify the environment variables it uses (not their values). When starting StepUp with a different value for any of these variables, StepUp will know that it has to repeat the step instead of skipping it.

One can only change an environment variable by stopping StepUp, changing the variable, and then starting StepUp again. One cannot modify environment variables while StepUp is running.

Example

Example source files: advanced_topics/environment_variables/

Create the following plan.py:

#!/usr/bin/env python
from stepup.core.api import step

step("echo ${MYVAR}", env="MYVAR")

Make it executable and run StepUp with a specific value of the variable:

chmod +x plan.py
MYVAR=foo stepup -n -w1

You will see the following output:

  DIRECTOR │ Listening on /tmp/stepup-########/director
  DIRECTOR │ Launched worker 0
     PHASE │ run
     START │ ./plan.py
   SUCCESS │ ./plan.py
     START │ echo ${MYVAR}
   SUCCESS │ echo ${MYVAR}
─────────────────────────────── Standard output ────────────────────────────────
foo
────────────────────────────────────────────────────────────────────────────────
  WORKFLOW │ Dumped to .stepup/workflow.mpk.xz
  DIRECTOR │ Stopping workers.
  DIRECTOR │ See you!

The variable substitution is performed in the subshell of the worker. StepUp will not try to substitute ${MYVAR} before starting the step. The special variables ${inp} and ${out} are exceptions to this rule, as discussed in the tutorial on dependencies.

Try the Following

  • Repeat MYVAR=foo stepup -n -w1 without making changes. You will see that the echo step is skipped as expected.

  • Now run MYVAR=bar stepup -n -w1. This time, the variable change will cause the step to be executed.