2.12. 環境変数#

ツールは制限された環境で実行されるため、親プロセスからほとんどの環境変数を引き継ぎません。 ツールの環境変数は、EnvVarRequirement を使って設定できます。

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 /home/docs/checkouts/readthedocs.org/user_builds/common-workflow-language-user-guide-ja/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-ja/checkouts/latest/src/_includes/cwl/environment-variables/env.cwl'
INFO [job env.cwl] /tmp/hw90yhjs$ env > /tmp/hw90yhjs/output.txt
INFO [job env.cwl] completed success
{
    "example_out": {
        "location": "file:///home/docs/checkouts/readthedocs.org/user_builds/common-workflow-language-user-guide-ja/checkouts/latest/src/_includes/cwl/environment-variables/output.txt",
        "basename": "output.txt",
        "class": "File",
        "checksum": "sha1$97176959ddcf527e9e218495216bac81b4c287a8",
        "size": 273,
        "path": "/home/docs/checkouts/readthedocs.org/user_builds/common-workflow-language-user-guide-ja/checkouts/latest/src/_includes/cwl/environment-variables/output.txt"
    }
}INFO Final process status is success
$ cat output.txt
HOME=/tmp/hw90yhjs
TMPDIR=/tmp/ymilozxn
PATH=/home/docs/checkouts/readthedocs.org/user_builds/common-workflow-language-user-guide-ja/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!