2.12. 环境变量#

CWL 工具运行于受限环境中,大多数环境变量都不会从父进程继承。 您可以使用 EnvVarRequirements 为该工具设置环境变量。

env.cwl#
#!/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
echo-job.yml#
message: Hello world!

现在,在命令行上以工具描述和输入对象为参数调用 cwltool:

$ cwltool env.cwl echo-job.yml
INFO /opt/hostedtoolcache/Python/3.9.19/x64/bin/cwltool 3.1.20240508115724
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/3saw3xo_$ env > /tmp/3saw3xo_/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$4627f25c3e2eda626f4c12476e473c946f08f964",
        "size": 407,
        "path": "/home/runner/work/user_guide/user_guide/src/_includes/cwl/environment-variables/output.txt"
    }
}INFO Final process status is success
$ cat output.txt
HOME=/tmp/3saw3xo_
TMPDIR=/tmp/379gcrgv
PATH=/opt/hostedtoolcache/Python/3.9.19/x64/bin:/opt/hostedtoolcache/Python/3.9.19/x64:/snap/bin:/home/runner/.local/bin:/opt/pipx_bin:/home/runner/.cargo/bin:/home/runner/.config/composer/vendor/bin:/usr/local/.ghcup/bin:/home/runner/.dotnet/tools:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
HELLO=Hello world!