Azure Batch 运行时环境变量Azure Batch runtime environment variables

Azure Batch 服务在计算节点上设置以下环境变量。The Azure Batch service sets the following environment variables on compute nodes. 可以在任务命令行中引用这些环境变量,也可在命令行运行的程序和脚本中引用它们。You can reference these environment variables in task command lines, and in the programs and scripts run by the command lines.

有关将环境变量用于 Batch 的详细信息,请参阅任务的环境设置For more information about using environment variables with Batch, see Environment settings for tasks.

环境变量的可见性Environment variable visibility

这些环境变量仅在任务用户(即执行任务的节点上的用户帐户)的上下文中可见。These environment variables are visible only in the context of the task user, the user account on the node under which a task is executed. 如果通过远程桌面协议 (RDP) 或安全外壳 (SSH) 远程连接到计算节点并列出环境变量,将看不到这些变量。You will not see these if you connect remotely to a compute node via Remote Desktop Protocol (RDP) or Secure Shell (SSH) and list the environment variables. 这是因为,用于远程连接的用户帐户与任务使用的帐户不同。This is because the user account that is used for remote connection is not the same as the account that is used by the task. 若要获取环境变量的当前值,请在 Windows 计算节点上启动 cmd.exe,或在 Linux 节点上启动 /bin/shTo get the current value of an environment variable, launch cmd.exe on a Windows compute node or /bin/sh on a Linux node:

cmd /c set <ENV_VARIABLE_NAME>

/bin/sh printenv <ENV_VARIABLE_NAME>

环境变量的命令行扩展Command-line expansion of environment variables

任务在计算节点上执行的命令行在 shell 下无法运行。The command lines executed by tasks on compute nodes do not run under a shell. 因此这些命令行无法以本机方式利用 shell 功能,例如环境变量扩展(包括 PATH)。Therefore, these command lines cannot natively take advantage of shell features such as environment variable expansion (this includes the PATH). 若要利用此类功能,必须在命令行中调用 shellTo take advantage of such features, you must invoke the shell in the command line. 例如,在 Windows 计算节点上启动 cmd.exe 或在 Linux 节点上启动 /bin/shFor example, launch cmd.exe on Windows compute nodes or /bin/sh on Linux nodes:

cmd /c MyTaskApplication.exe %MY_ENV_VAR%

/bin/sh -c MyTaskApplication $MY_ENV_VAR

环境变量Environment variables

变量名称Variable name 说明Description 可用性Availability 示例Example
AZ_BATCH_ACCOUNT_NAMEAZ_BATCH_ACCOUNT_NAME 任务所属的 Batch 帐户名。The name of the Batch account that the task belongs to. 所有任务。All tasks. mybatchaccountmybatchaccount
AZ_BATCH_ACCOUNT_URLAZ_BATCH_ACCOUNT_URL Batch 帐户的 URL。The URL of the Batch account. 所有任务。All tasks. https://myaccount.chinanorth.batch.chinacloudapi.cn
AZ_BATCH_APP_PACKAGEAZ_BATCH_APP_PACKAGE 所有应用包环境变量的前缀。A prefix of all the app package environment variables. 例如,如果应用程序“Foo”版本“1”已安装到池,则环境变量为 AZ_BATCH_APP_PACKAGE_FOO_1。For example, if Application “Foo” version “1” is installed onto a pool, the environment variable is AZ_BATCH_APP_PACKAGE_FOO_1. AZ_BATCH_APP_PACKAGE_FOO_1 指向包下载到的位置(文件夹)。AZ_BATCH_APP_PACKAGE_FOO_1 points to the location which the package was downloaded (a folder). 包含关联应用包的任何任务。Any task with an associated app package. 如果节点本身拥有应用程序包,则还可用于所有任务。Also available for all tasks if the node itself has application packages. AZ_BATCH_APP_PACKAGE_FOO_1AZ_BATCH_APP_PACKAGE_FOO_1
AZ_BATCH_AUTHENTICATION_TOKENAZ_BATCH_AUTHENTICATION_TOKEN 一种身份验证令牌,用于授予对一组有限的 Batch 服务操作的访问权限。An authentication token that grants access to a limited set of Batch service operations. 仅当添加任务时设置 authenticationTokenSettings 时,才会显示此环境变量。This environment variable is only present if the authenticationTokenSettings are set when the task is added. 令牌值在 Batch API 中用作凭据以创建 Batch 客户端,例如在 BatchClient.Open() .NET API 中。The token value is used in the Batch APIs as credentials to create a Batch client, such as in the BatchClient.Open() .NET API. 所有任务。All tasks. OAuth2 访问令牌OAuth2 access token
AZ_BATCH_CERTIFICATES_DIRAZ_BATCH_CERTIFICATES_DIR 任务工作目录内的目录,会在其中为 Linux 计算节点存储证书。A directory within the task working directory in which certificates are stored for Linux compute nodes. 请注意,此环境变量不适用于 Windows 计算节点。Note that this environment variable does not apply to Windows compute nodes. 所有任务。All tasks. /mnt/batch/tasks/workitems/batchjob001/job-1/task001/certs/mnt/batch/tasks/workitems/batchjob001/job-1/task001/certs
AZ_BATCH_HOST_LISTAZ_BATCH_HOST_LIST nodeIP,nodeIP 格式列出了分配给多实例任务的节点的列表。The list of nodes that are allocated to a multi-instance task in the format nodeIP,nodeIP. 多实例主要和子任务。Multi-instance primary and subtasks. 10.0.0.4,10.0.0.5
AZ_BATCH_IS_CURRENT_NODE_MASTERAZ_BATCH_IS_CURRENT_NODE_MASTER 指定当前节点是否为多实例任务的主节点。Specifies whether the current node is the master node for a multi-instance task. 可能的值为 truefalsePossible values are true and false. 多实例主要和子任务。Multi-instance primary and subtasks. true
AZ_BATCH_JOB_IDAZ_BATCH_JOB_ID 任务所属的作业的 ID。The ID of the job that the task belongs to. 除启动任务以外的所有任务。All tasks except start task. batchjob001batchjob001
AZ_BATCH_JOB_PREP_DIRAZ_BATCH_JOB_PREP_DIR 节点上作业准备任务目录的完整路径。The full path of the job preparation task directory on the node. 除启动任务和作业准备任务之外的所有任务。All tasks except start task and job preparation task. 仅当使用作业准备任务来配置作业时才适用。Only available if the job is configured with a job preparation task. C:\user\tasks\workitems\jobprepreleasesamplejob\job-1\jobpreparationC:\user\tasks\workitems\jobprepreleasesamplejob\job-1\jobpreparation
AZ_BATCH_JOB_PREP_WORKING_DIRAZ_BATCH_JOB_PREP_WORKING_DIR 节点上作业准备任务工作目录的完整路径。The full path of the job preparation task working directory on the node. 除启动任务和作业准备任务之外的所有任务。All tasks except start task and job preparation task. 仅当使用作业准备任务来配置作业时才适用。Only available if the job is configured with a job preparation task. C:\user\tasks\workitems\jobprepreleasesamplejob\job-1\jobpreparation\wdC:\user\tasks\workitems\jobprepreleasesamplejob\job-1\jobpreparation\wd
AZ_BATCH_MASTER_NODEAZ_BATCH_MASTER_NODE 运行多实例任务的主要任务的计算节点的 IP 地址和端口。The IP address and port of the compute node on which the primary task of a multi-instance task runs. 多实例主要和子任务。Multi-instance primary and subtasks. 10.0.0.4:6000
AZ_BATCH_NODE_IDAZ_BATCH_NODE_ID 任务分配到的节点的 ID。The ID of the node that the task is assigned to. 所有任务。All tasks. tvm-1219235766_3-20160919t172711ztvm-1219235766_3-20160919t172711z
AZ_BATCH_NODE_IS_DEDICATEDAZ_BATCH_NODE_IS_DEDICATED 如果为 true,则当前节点是一个专用节点。If true, the current node is a dedicated node. 所有任务。All tasks. true
AZ_BATCH_NODE_LISTAZ_BATCH_NODE_LIST nodeIP;nodeIP 格式列出了分配给多实例任务的节点的列表。The list of nodes that are allocated to a multi-instance task in the format nodeIP;nodeIP. 多实例主要和子任务。Multi-instance primary and subtasks. 10.0.0.4;10.0.0.5
AZ_BATCH_NODE_MOUNTS_DIRAZ_BATCH_NODE_MOUNTS_DIR 所有装载目录所在的节点级别文件系统装载位置的完整路径。The full path of the node level [file system mount location where all mount directories reside. Windows 文件共享使用驱动器号,因此对于 Windows,装载驱动器是设备和驱动器的一部分。Windows file shares use a drive letter, so for Windows, the mount drive is part of devices and drives. 如果用户知道装载目录的装载权限,则所有任务(包括启动任务)都有权访问该用户。All tasks including start task have access to the user, given the user is aware of the mount permissions for the mounted directory. 例如,在 Ubuntu 中,位置为:/mnt/batch/tasks/fsmountsIn Ubuntu, for example, the location is: /mnt/batch/tasks/fsmounts
AZ_BATCH_NODE_ROOT_DIRAZ_BATCH_NODE_ROOT_DIR 节点上所有批处理目录的根目录的完整路径。The full path of the root of all Batch directories on the node. 所有任务。All tasks. C:\user\tasksC:\user\tasks
AZ_BATCH_NODE_SHARED_DIRAZ_BATCH_NODE_SHARED_DIR 节点上共享目录的完整路径。The full path of the shared directory on the node. 节点上执行的所有任务具有此目录的读取/写入权限。All tasks that execute on a node have read/write access to this directory. 在其他节点上执行的任务没有对此目录(它不是“共享”的网络目录)的远程访问权限。Tasks that execute on other nodes do not have remote access to this directory (it is not a "shared" network directory). 所有任务。All tasks. C:\user\tasks\sharedC:\user\tasks\shared
AZ_BATCH_NODE_STARTUP_DIRAZ_BATCH_NODE_STARTUP_DIR 节点上启动任务目录的完整路径。The full path of the start task directory on the node. 所有任务。All tasks. C:\user\tasks\startupC:\user\tasks\startup
AZ_BATCH_POOL_IDAZ_BATCH_POOL_ID 运行任务的池的 ID。The ID of the pool that the task is running on. 所有任务。All tasks. batchpool001batchpool001
AZ_BATCH_TASK_DIRAZ_BATCH_TASK_DIR 节点上任务目录的完整路径。The full path of the task directory on the node. 此目录包含任务的 stdout.txtstderr.txt,以及 AZ_BATCH_TASK_WORKING_DIR。This directory contains the stdout.txt and stderr.txt for the task, and the AZ_BATCH_TASK_WORKING_DIR. 所有任务。All tasks. C:\user\tasks\workitems\batchjob001\job-1\task001C:\user\tasks\workitems\batchjob001\job-1\task001
AZ_BATCH_TASK_IDAZ_BATCH_TASK_ID 当前任务的 ID。The ID of the current task. 除启动任务以外的所有任务。All tasks except start task. task001task001
AZ_BATCH_TASK_SHARED_DIRAZ_BATCH_TASK_SHARED_DIR 一个目录路径,对于多实例任务的主要任务和每个子任务来说都相同。A directory path that is identical for the primary task and every subtask of a multi-instance task. 该路径存在于运行多实例任务的每个节点上,并且在该节点上运行的任务命令(协调命令应用程序命令)对其具有读取/写入权限。The path exists on every node on which the multi-instance task runs, and is read/write accessible to the task commands running on that node (both the coordination command and the application command). 在其他节点上执行的子任务或主要任务不具有对此目录(它不是“共享”的网络目录)的远程访问权限。Subtasks or a primary task that execute on other nodes do not have remote access to this directory (it is not a “shared” network directory). 多实例主要和子任务。Multi-instance primary and subtasks. C:\user\tasks\workitems\multiinstancesamplejob\job-1\multiinstancesampletaskC:\user\tasks\workitems\multiinstancesamplejob\job-1\multiinstancesampletask
AZ_BATCH_TASK_WORKING_DIRAZ_BATCH_TASK_WORKING_DIR 节点上任务工作目录的完整路径。The full path of the task working directory on the node. 当前正在运行的任务具有对此目录的读取/写入权限。The currently running task has read/write access to this directory. 所有任务。All tasks. C:\user\tasks\workitems\batchjob001\job-1\task001\wdC:\user\tasks\workitems\batchjob001\job-1\task001\wd
CCP_NODESCCP_NODES 分配给多实例任务的节点和每个节点的核心数的列表。The list of nodes and number of cores per node that are allocated to a multi-instance task. 使用 numNodes<space>node1IP<space>node1Cores<space> 格式列出了节点和内核Nodes and cores are listed in the format numNodes<space>node1IP<space>node1Cores<space>
node2IP<space>node2Cores<space> ...,其中节点数后跟一个或多个节点 IP 地址和每个节点的内核数。node2IP<space>node2Cores<space> ..., where the number of nodes is followed by one or more node IP addresses and the number of cores for each.
多实例主要和子任务。Multi-instance primary and subtasks. 2 10.0.0.4 1 10.0.0.5 1