Environment Variables

Overview

Teaching: 10 min
Exercises: 0 min
Questions
  • How do I set the value of environment variables for a tool’s execution?

Objectives
  • Learn how to pass environment variables to a tool’s runtime.

Tools run in a restricted environment and do not inherit most environment variables from the parent process. You can set environment variables for the tool using EnvVarRequirement.

env.cwl

#!/usr/bin/env cwl-runner

cwlVersion: v1.0
class: CommandLineTool
baseCommand: env
requirements:
  EnvVarRequirement:
    envDef:
      HELLO: $(inputs.message)
inputs:
  message: string
outputs: []

echo-job.yml

message: Hello world!

Now invoke cwl-runner with the tool wrapper and the input object on the command line:

$ cwl-runner env.cwl echo-job.yml
[job 140710387785808] /home/example$ env
PATH=/bin:/usr/bin:/usr/local/bin
HELLO=Hello world!
TMPDIR=/tmp/tmp63Obpk
Final process status is success
{}

Key Points

  • Tools run in a restricted environment with a minimal set of environment variables.

  • Use the EnvVarRequirement field to set environment variables inside a tool’s environment.