2.12. Environment Variables#

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:
  example_out:
    type: stdout
stdout: output.txt
echo-job.yml#
message: Hello world!

Now invoke cwltool with the tool description and the input object on the command line:

$ cwltool env.cwl echo-job.yml
INFO /opt/hostedtoolcache/Python/3.9.13/x64/bin/cwltool 3.1.20220913185150
INFO Resolved 'env.cwl' to 'file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/environment-variables/env.cwl'
INFO [job env.cwl] /tmp/kyif_0xm$ env > /tmp/kyif_0xm/output.txt
INFO [job env.cwl] completed success
{
    "example_out": {
        "location": "file:///home/runner/work/user_guide/user_guide/src/_includes/cwl/environment-variables/output.txt",
        "basename": "output.txt",
        "class": "File",
        "checksum": "sha1$f0f16821d876e185548f30729f6fbb53cdd6e80f",
        "size": 470,
        "path": "/home/runner/work/user_guide/user_guide/src/_includes/cwl/environment-variables/output.txt"
    }
}
INFO Final process status is success
$ cat output.txt
Message is: Hello world!