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
.
#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: CommandLineTool
baseCommand: env
requirements:
EnvVarRequirement:
envDef:
HELLO: $(inputs.message)
inputs:
message: string
outputs:
example_out:
type: stdout
stdout: output.txt
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 /home/docs/checkouts/readthedocs.org/user_builds/common-workflow-language-user-guide-pt-br/envs/latest/bin/cwltool 3.1.20240508115724
INFO Resolved 'env.cwl' to 'file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-language-user-guide-pt-br/checkouts/latest/src/_includes/cwl/environment-variables/env.cwl'
INFO [job env.cwl] /tmp/4ba6gkp9$ env > /tmp/4ba6gkp9/output.txt
INFO [job env.cwl] completed success
{
"example_out": {
"location": "file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-language-user-guide-pt-br/checkouts/latest/src/_includes/cwl/environment-variables/output.txt",
"basename": "output.txt",
"class": "File",
"checksum": "sha1$fb3d2c7cd7204cf29d62c67421ec2cad5f2ac04f",
"size": 276,
"path": "/home/docs/checkouts/readthedocs.org/user_builds/common-workflow-language-user-guide-pt-br/checkouts/latest/src/_includes/cwl/environment-variables/output.txt"
}
}INFO Final process status is success
$ cat output.txt
HOME=/tmp/4ba6gkp9
TMPDIR=/tmp/fv4q1bgw
PATH=/home/docs/checkouts/readthedocs.org/user_builds/common-workflow-language-user-guide-pt-br/envs/latest/bin:/home/docs/.asdf/shims:/home/docs/.asdf/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HELLO=Hello world!